Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to XML with XSL multiple elements

Status
Not open for further replies.

strut

Programmer
Jan 29, 2002
5
US
i have a document a.xml with tags

<OldPhone>
<PhoneNumber>123-456-789</PhoneNumber>
<Description>HOME</Description>
</OldPhone>
<OldPhone>
<PhoneNumber>222-777-3333</PhoneNumber>
<Description>WORK</Description>
</OldPhone>

i need to get to b.xml that looks like this.

<tag name=IM2>123-456-789</tag>
<tag name=IM3>222-777-3333</tag>

I have created an XSL document that will put the first number into both fields, but i can not figure out how to get the work and home phone seperate.

my xsl

<tag name=&quot;IM2&quot;>
<xsl:value-of select=&quot;.//OldPhone/Number&quot;/>
</tag>


this gives the first phone number in both fields. Ideas?

 
You might want to use the xsl:choose function to select out the work number. The xsl below should give you a start with the corresponding xml located after it.

Fred

<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;<xsl:template match=&quot;/&quot;>
<root>
<xsl:for-each select=&quot;//OldPhone&quot;>
<tag>
<xsl:attribute name=&quot;name&quot;>
<xsl:choose>
<xsl:when test=&quot;Description='HOME'&quot;>IM2</xsl:when>
<xsl:when test=&quot;Description='WORK'&quot;>IM3</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select=&quot;PhoneNumber&quot;/>
</tag>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>

XML:
<Root>
<OldPhone>
<PhoneNumber>123-456-789</PhoneNumber>
<Description>HOME</Description>
</OldPhone>
<OldPhone>
<PhoneNumber>222-777-3333</PhoneNumber>
<Description>WORK</Description>
</OldPhone>
</Root>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top