I want to write a template to process some section and reuse it.
In the below XML, we see Message is repeated in every ,,. I want to write a template to process and call it when ever needed.
<Data>
<A>
<text>this is text</text>
<Message>
<local>Local link</local>
<STD>External link</STD>
</Message>
</A>
<B>
<info>Information</info>
<Message>
<local>Local uri link</local>
<STD>External link uri</STD>
</Message>
</B>
<C>
<longtext>Long Text</longtext>
<Message>
<local>Local uri link</local>
<STD>External link uri</STD>
</Message>
</C>
<Data>
Output needed:
<Information>
<AA>
this is text
<MSG local value="Local uri link" STD value="External link"/>
</AA>
<BB>
Information
<MSG local value ="Local uri link" STD value="External link"/>
</BB>
<CC>
Long Text
<MSG local value="Local uri link" STD value="External link"/>
</CC>
<Information>
While processing tag in every node, I am writing code for every tags in A, B, C.
Sample code written
<Information>
<xsl:template match="A">
<AA>
<xsl:value-of select="text"/>
<xsl:element name="MSG">
<xsl:attribute name="local value">
<xsl:value-of select="Message/local"/>
</xsl:attribute>
<xsl:attribute name="STD value">
<xsl:value-of select="Message/STD"/>
</xsl:attribute>
</AA>
</Information>
similarly for every template I am explicitly writing the code for the block MSG.
Now I want to write a separate template to process . And I want to call this template from every template.
Basically I want to reuse the code written to process
Can any one help me how to do it.
Thank you.
Here is a sample:
When applied to the input
Saxon 6.5.5 outputs
Neither your posted input sample nor the wanted output sample are well-formed XML so I had to make some changes to element or attribute names to process as well as to output XML.