Right now, I’m able to grab the immediate children of a certain element “root” and these elements have names that contain dashes. So for example, say these immediate children have names ‘A4-1′,’B3-2’, and ‘C4-3’.
I would like to be able to do something along the lines of the following psuedo-code:
for each immediate child
print out it's child element figtitle/autonum/@ID
Is there a way to do something like this without concatenating the path into a string? Each time I concat the immediate child values to the rest of its path, I get a string, so I can’t compare it’s attribute value to another value, for example:
<xsl:if test="*['yes' = (PATH)]">
<xsl:value-of select="PATH[@ID = 'yes']"/>
</xsl:if>
Where the paths would be:
root/A4-1/figtitle/autonum/@ID
root/B3-2/figtitle/autonum/@ID
root/C4-3/figtitle/autonum/@ID
The expression you need is:
this means:
Select all
IDattributes of anyautonumelement that is a child of afigtitleelement that is a grandchild of the top elementroot.If the element
rootisn’t the top element of the document, then if the expression would be evaluated with the parent ofrootas the context node, the expression should be:Explanation:
The expression:
selects all elements that are children of the element named
someElementthat is a child of the context node (current node) against which the expression is evaluated.Thus, it is not at all necessary to enumerate explicitly the names of the children of
someElement.Update: The OP has clarified in a comment that she needs to select only those children of
root, whose names contain dashes, numbers and letters.This XPath expression:
root/*[contains(name(), ‘-‘)
and
translate(name(), $vAlphaNum, ‘ ‘) = ”]
/figtitle/autonum/@ID
selects exactly all such elements.
Here, the variable
$vAlphaNummust be defined to contain all lower and upper case letters and the digits 0-9.In XSLT 2.0 one can use the
matches()function with a suitable regular expression.