concatenating two xPaths in XSLT -
in xslt script i'm calling recursive template , want pass xpath parameter each iteration. in each iteration want concatenate child's xpath(*/)
current path (please refer code). i'm using concat() function, since returns string, i'm unable use path print content of path.
<xsl:copy-of select="$path" /> <!--this requests xpath, not string-->
so can 1 tell me how concatenate 2 xpaths or how convert string xpath.
thank you.
<xsl:template match="/"> <xsl:call-template name="repeatable" > <xsl:with-param name="limit" select="10" /> </xsl:call-template> </xsl:template> <xsl:template name="repeatable"> <xsl:param name="index" select="1" /> <xsl:param name="limit" select="1" /> <xsl:param name="path" select="@*" /> <xsl:copy-of select="$path" /> <xsl:if test="($limit >= $index)"> <xsl:call-template name="repeatable"> <xsl:with-param name="index" select="$index + 1" /> <xsl:with-param name="path" select="concat('*/', $path)" /> </xsl:call-template> </xsl:if> </xsl:template>
while i'm waiting respond question above, here's xslt seem be trying do:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" indent="yes" omit-xml-declaration="yes"/> <xsl:template match="@*"> <xsl:value-of select="concat(name(), ' = ', ., '
')"/> </xsl:template> <xsl:template match="/"> <xsl:call-template name="repeatable" > <xsl:with-param name="limit" select="10" /> </xsl:call-template> </xsl:template> <xsl:template name="repeatable"> <xsl:param name="index" select="1" /> <xsl:param name="limit" select="1" /> <xsl:param name="current" select="." /> <xsl:apply-templates select="$current/@*" /> <xsl:if test="($limit >= $index)"> <xsl:call-template name="repeatable"> <xsl:with-param name="index" select="$index + 1" /> <xsl:with-param name="limit" select="$limit" /> <xsl:with-param name="current" select="$current/*" /> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet>
when run on following input:
<root a1="a" a2="b"> <cont a3="c" a4="d"> <child a5="e" a6="f" /> </cont> <cont a7="g" a8="h"> <child a9="i" a10="j"> <subchild a11="k" a12="l" /> </child> </cont> </root>
the result is:
a1 = a2 = b a3 = c a4 = d a7 = g a8 = h a5 = e a6 = f a9 = a10 = j a11 = k a12 = l
is close trying do? if not, please clarify.
Comments
Post a Comment