xpath - XSLT: Test if node exists regardless if it's a child or grandchild of current node -


i'm working on xslt transformations , i've found out there might or might not node between current parent , it's clildren, depending on external factors. have change xslt code in order deal both of these scenarios:

scenario 1:

<parent>    <child/>    <child/> <parent> 

scenario 2:

<parent>    <nuisance>       <child/>       <child/>    </nuisance> <parent> 

i have situations in test="parent/child" or otherwise use format of accessing parent/node.

i need test="parent/magic(* or none)/child"

they way know of can solve problem use:

<xsl:choose>     <xsl:when test="parent/child">        <!-- select="parent/child"-->                 </xsl:when>      <xsl:otherwise>        <!-- select="parent/*/child"-->           </xsl:otherwise> </xsl:choose> 

but triple code in size , lot of manual labour...

help appreciated!

why not select union of two?

<xsl:apply-templates select="parent/child|parent/*/child"/> 

this select correct nodes in both cases.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -