XSLT: Match N-level node

StockplayDP

New Member
Need to match node by id. (say a2-2)XML:\[code\]<node id="a" title="Title a"> <node id="a1" title="Title a1" /> <node id="a2" title="Title a2" > <node id="a2-1" title="Title a2-1" /> <node id="a2-2" title="Title a2-2" /> <node id="a2-3" title="Title a2-3" /> </node> <node id="a3" title="Title a3" /></node><node id="b"> <node id="b1" title="Title b1" /></node>\[/code\]Current Solution:\[code\]<xsl:apply-templates select="node" mode="all"> <xsl:with-param name="id" select="'a2-2'" /></xsl:apply-templates> <xsl:template match="node" mode="all"> <xsl:param name="id" /> <xsl:choose> <xsl:when test="@id=$id"> <xsl:apply-templates mode="match" select="." /> </xsl:when> <xsl:otherwise> <xsl:apply-templates mode="all" select="node"> <xsl:with-param name="id" select="$id" /> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="node" mode="match"> <h3><xsl:value-of select="@title"/>.</h3> </xsl:template>\[/code\]Problem:
Above solution seem to be very bulky for a quite common problem.
Am I over-complicating? Is there a simpler solution.
 
Back
Top