Paste XPath while copying using application templates

I created XSLT using an identity template and several templates that match potential XPath in the source. However, ways of matching do not always exist. Is there a way to β€œinsert” the path before applying the matching pattern? Since I know that XSLT is not executed procedurally, I was not sure how to do this. Examples are below.

Let's say this is XSLT:

<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:if> </xsl:template> <xsl:template match='pathA'> do stuff </xsl:template> <xsl:template match='pathB'> do something </xsl:template> <xsl:template match='pathC'> do other stuff </xsl:template> 

And let's say this on the tab:

 <root> <Child> <pathA>I have Data!</pathA> <pathC>We skipped B!</pathC> </Child> </root> 

Is there a way to β€œcreate” pathB so that the XPath matching template can execute?

Thanks again for the help!

+1
source share
1 answer
Good. What about...
 <xsl:template name="pathB"> <xsl:param name="nodes"/> do something </xsl:template> <xsl:template match="Child"> <xsl:copy> <xsl:apply-templates select="@* | pathA[not(../pathB)] | pathB/preceding-sibling::node()"/> </xsl:copy> <xsl:call-template name="pathB"> <!-- pass the set of elements of type "pathB", possibly an empty nodeset --> <xsl:with-param name="nodes" select="pathB"/> </xsl:call-template> <xsl:copy> <xsl:apply-templates select="node()[not(self::pathA) and not(../pathB)] | pathB/following-sibling::node()"/> </xsl:copy> <xsl:template> 
+1
source

All Articles