how to get xml node value in xslt

I’m new to xslt programming and I need to do xml to xml transformation using xslt.

following is my xml document

  <item type="stock" exch="nyse"   symbol="ZCXM" company="zacx corp"
  <item type="stock" exch="nasdaq" symbol="ZFFX" company="zaffymat inc"
  <item type="stock" exch="nasdaq" symbol="ZYSZ" company="zysmergy inc"

I need to change this xml structure as follows

  <stock exchange="nyse">
    <name>zacx corp</name>
  <stock exchange="nasdaq">
    <name>zaffymat inc</name>
  <stock exchange="nasdaq">
    <name>zysmergy inc</name>

so, I wrote the xsl document as follows,

<xsl:stylesheet xmlns:xsl="" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
    <xsl:for-each select="investments/item[@type='stock']">
        <xsl:attribute name="exchange">
            <xsl:value-of select="@exch"/>
        <name><xsl:value-of select="@company"/></name>
        <symbol><xsl:value-of select="@symbol"/></symbol>
        <price><xsl:value-of select="@price"/></price>


There are no cording errors, but xslt document is not getting the xml node. in xml to html transformation I can simply link xml and xslt using <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> and get xml nodes.
But i’m confused how can I link xml and xslt when doing the xml to xml transformation.

any suggestions how I can do it?

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.