XML transform with XSLT 1



today im really struggling with XSLT, it has been a long time that i had to use it. I have to edit some xml and i can't use XSLT 2.0. So i have to use 1.0. The xml im struugling with is (basic example) :


I tried making an template for the 2 nodes, and then 'call' that template to create a new node with the desired values but that didnt work either , im missing something if someone can point me into the right direction.





<messagemap>
<author>
<au_id>274-80-9391</au_id>
<au_lname>Straight</au_lname>
<au_fname>Dean</au_fname>
<phone>415 834-2919</phone>
<address>5420 College Av.</address>
<city>Oakland</city>
<state>CA</state>
<zip>94609</zip>
<contract>1</contract>
</author>
</messagemap>



XM:





<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output indent="yes"/>
<!--Identity Transform.-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="au_fname | au_lname">
<company>
<xsl:value-of select="."/>
</company>
</xsl:template>
</xsl:stylesheet>



What i get as a result:





<messagemap>
<author>
<au_id>274-80-9391</au_id>
<company>Straight</company>
<company>Dean</company>
<phone>415 834-2919</phone>
<address>5420 College Av.</address>
<city>Oakland</city>
<state>CA</state>
<zip>94609</zip>
<contract>1</contract>
</author>
</messagemap>



What i need is:





<messagemap>
<author>
<au_id>274-80-9391</au_id>
<company>Dean Straight</company>
<phone>415 834-2919</phone>
<address>5420 College Av.</address>
<city>Oakland</city>
<state>CA</state>
<zip>94609</zip>
<contract>1</contract>
</author>
</messagemap>



No comments:

Post a Comment