Skip to main content
1-Visitor
April 24, 2012
Question

help with XPATH

  • April 24, 2012
  • 14 replies
  • 2857 views

how can I have a tag check its content? I can't use starts-with because I want the answer to be "1" and there is also a "10".


I am looking for when hazid = 1 or the first time hazid has content.


(And how would another tag check hazid's content?)



Thanks!

    14 replies

    1-Visitor
    April 26, 2012
    I oversimplified a bit in just saying that XPath converts the value to a
    boolean. The XPath engine does the conversion at the request of the
    caller, since it wants a boolean value in order to decide if it should
    proceed with the condition.

    Depending on which output type you're working with, doing a "View Source"
    in Styler and searching for your XPath expression will probably turn up
    that it has been wrapped in a call to the "boolean" XPath function, which
    does the conversion. Some outputs won't have this call, since the context
    (such as the "test" attribute of an xsl:if or xsl:when, for an XSLT-based
    output) implies a boolean conversion.

    -Brandon 🙂


    On Thu, Apr 26, 2012 at 1:46 AM, Caroline Leccese <
    caroline@thecodesource.net> wrote:

    > Thanks, everyone!
    >
    > following-sibling::hazid[1][normalize-space(.) = '1'] worked as I wished.
    >
    > I didn't know that XPATH converts the value to a boolean. How would you
    > get it to return the actual value?
    >
    1-Visitor
    April 26, 2012
    The issue that was causing the undesired results in this case was the
    presence of multiple "hazid" elements, all of which were following siblings
    of the context node, an "icon" element. The expression suggested below
    would return any such element that matched the "[text()='1']" predicate,
    but what is desired is for the condition to only return true if the first
    such element matches, thus the addition of the "[1]" predicate.

    The change suggested here, using "text()" instead of ".", would work for
    the given use case, though it probably would not provide any advantage and
    may even fail in certain cases where "." would not. The difference is that
    while "." will concatenate all of the text contained within the "hazid"
    element, at any level, "text()" will only check that some contiguous string
    of text immediately inside of the "hazid" matches the "1" string. If there
    is any other markup inside of the "hazid" element, such as
    "<hazid><value>1</value></hazid>", this test would fail, since the "1" text
    node is not an immediate child of "hazid".

    Another edge case where the difference might be seen is a PI occurring
    between two characters. Say you're looking for "12" instead of just "1".
    If you happen to have saved your document with the cursor in the wrong
    place, your style sheet might get something like "<hazid>1Caret?>2</hazid>". Since there is no text node here with a string value of
    "12" (the "1" and "2" are two separate nodes), the test would fail.

    -Brandon 🙂


    On Thu, Apr 26, 2012 at 4:58 AM, DENIARD.Yves <yves.deniard@mbda-systems.com<br/>> wrote:

    > ****
    >
    > Hello,****
    >
    > ** **
    >
    > Why don’t you use the simple test :****
    >
    > following-sibling::hazid[text()=’1’]****
    >
    > ** **
    >
    > does it also return true when hazid is empty ?****
    >
    > ** **
    >
    > Yves Deniard****
    >
    > MBDA ****France********
    cleccese1-VisitorAuthor
    1-Visitor
    April 26, 2012

    following-sibling::hazid[text()='1'] returned the same results as following-sibling::hazid[. = '1'] with TRUE in the empty hazids.

    1-Visitor
    April 30, 2012
    From a co-worker:

    I want to know when the value of a specific attribute on a specific tag has changed. I was hoping there would be an event/callback available for the Modify Attributes dialog - for instance, after the OK button is clicked - but I can only find a "before" event ("modify_tag" allows you to modify values and behavior before the dialog appears). Is the answer to use the "dlgitem_add_callback" function? If so, how do I use that set of functions to zero in on Modify Attributes, while knowing the tag and changed attribute(s)?

    I'm having trouble with the PDF Customizer's Guide, which may have answers, so I'm taking the easy route for now!