Xpath Query Help. Selecting data from multiple paths as a single data set -
i have xml structure following :
<doc> <line void="false"> <linenumber>1</linenumber> <info1>ddddd</info1> <info2>aaaaa</info2> </line> <line void="true"> <linenumber>2</linenumber> <voidlinenumber>1</voidlinenumber> <voidvalue>2.00</voidvalue> </line> </doc>
i need 1 single set of data. select lines void = false voidlinenumber , voidvalue data line void = true , voidlinenumber = linenumber original line.
is possible? appreciated. thanks
as michael kay noted, xpath can used select nodes, not transform them. can want xslt:
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" encoding="utf-8" indent="yes" /> <xsl:template match="doc"> <xsl:apply-templates select="line" /> </xsl:template> <xsl:template match="line"> <xsl:variable name="voidvalue"><xsl:value-of select="@void" /></xsl:variable> <xsl:if test="$voidvalue='false'"> <xsl:copy> <xsl:copy-of select="@*" /> <xsl:apply-templates /> </xsl:copy> </xsl:if> </xsl:template> <xsl:template match="*"> <xsl:element name="{name()}"> <xsl:if test="name(.)='linenumber'"> <xsl:value-of select="."/> </xsl:if> </xsl:element> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment