I have a xsl:template that is inserting an additional node into my original XML.
I would then like to use the following Template to reference that new node to assist in the continuation of the parsing of the source file.
My current method (second template) does not 'see' the newly inserted node from the first template. How would I approach this?
Many Thanks.
The below examples are extremely simplified to express what I am trying to achieve.
Starting XML:
<master>
<node>
<node1>hi</node1>
<node2>bye</node2>
</node>
</master>
First Template:
<xsl:template match="master/node">
<node>
<xsl:apply-templates/>
<node3>greetings</node3>
</node>
</xsl:template>
Result XML 1:
<master>
<node>
<node1>hi</node1>
<node2>bye</node2>
<node3>greetings<node3>
</node>
</master>
Second Template:
<xsl:template match="master/node[node3='greetings']">
<node>
<newnode><xsl:value-of select="./node3"/>
</node>
</xsl:template>
Expected Result:
<master>
<node>
<newnode>greetings</newnode>
</node>
</master>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- first template -->
<xsl:template match="master/node">
<node>
<xsl:apply-templates/>
<node3>greetings</node3>
</node>
</xsl:template>
<!-- second template -->
<xsl:template match="master/node[node3='greetings']">
<node>
<newnode><xsl:value-of select="./node3"/></newnode>
</node>
</xsl:template>