xslt - XPATH to display based on conditional value -
<chapter> <concept> <title>*********************</title> . . </concept> <sections> <title>*******************</title> </chapter> in above structure retrieve text <concept><title> or <sections><title>. i.e. using 1 xpath condition need value below conditions.
1) if <concept><title> not appeared <sections><title>. vice verso also..
2) both title available there want consider nearst node value. i.e. in above structure "<sections><title>" latest node.
you want "nearest" (first) of two:
(/*/*[self::concept or self::sections]/title)[1] if want "latest" (last) of them, use:
(/*/*[self::concept or self::sections]/title)[last()] xslt - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="/"> <xsl:copy-of select= "(/*/*[self::concept or self::sections]/title)[1]"/> =============== <xsl:copy-of select= "(/*/*[self::concept or self::sections]/title)[last()]"/> </xsl:template> </xsl:stylesheet> when transformation applied on following xml document:
<chapter> <concept> <title>*********title 1************</title> . . </concept> <sections> <title>**********title 2*********</title> </sections> </chapter> the 2 xpath expressions evaluated , results copied output:
<title>*********title 1************</title> =============== <title>**********title 2*********</title>
Comments
Post a Comment