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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT and namespaces in XML nodes

Status
Not open for further replies.

Hexonx

Programmer
Jan 10, 2001
102
US
I'm transforming a document from one XML schema to another using MSXML 4.0. One of the elements in the stylesheet has a namespace reference in the element node. The value of this node is populated with <xsl:value-of >. When executing the transform, I get a parse error: &quot;value-of not allowed in this context&quot;.

Source document (investments.xml)
<?xml version=&quot;1.0&quot;?>
<investments>
<item type=&quot;stock&quot; exch=&quot;nyse&quot; symbol=&quot;ZCXM&quot; company=&quot;zacx corp&quot;
price=&quot;28.875&quot;/>
<item type=&quot;stock&quot; exch=&quot;nasdaq&quot; symbol=&quot;ZFFX&quot; company=&quot;zaffymat inc&quot;
price=&quot;92.250&quot;/>
<item type=&quot;stock&quot; exch=&quot;nasdaq&quot; symbol=&quot;ZYSZ&quot; company=&quot;zysmergy inc&quot;
price=&quot;20.313&quot;/>
</investments>

Stylesheet(portfolio.xsl)
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;xml&quot; indent=&quot;yes&quot;/>
<xsl:template match=&quot;/&quot;>
<portfolio xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot;>
<xsl:for-each select=&quot;investments/item[@type='stock']&quot;>
<stock>
<xsl:attribute name=&quot;exchange&quot;>
<xsl:value-of select=&quot;@exch&quot;/>
</xsl:attribute>
<name><xsl:value-of select=&quot;@company&quot;/></name>
<symbol><xsl:value-of select=&quot;@symbol&quot;/></symbol>
<price><xsl:value-of select=&quot;@price&quot;/></price>
<!--
This line is from the original MSXML 4.0 SDK docs,
but causes an error: &quot;value-of not allowed in this context&quot;.
Removing the namespace declaration resolves the problem.
<price dt:dt=&quot;number&quot;><xsl:value-of select=&quot;@price&quot;/></price>
-->
</stock>
</xsl:for-each>
</portfolio>
</xsl:template>
</xsl:stylesheet>

Why would the &quot;dt&quot; namespace have any effect on the transform? It's in the static text of the template!

BTW - This came from the MSXML 4.0 SDK docs. Search for 'Translating from One XML Schema to Another'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top