Hello there,
Recent I met the problem to deal with the element with ns, what does "ns" mean here. I supposed it means namespace, like
Code:
<ns0:PO xmlns:ns0="http://HelloWorld.POSchema"></ns0>
When I tried to use XSLT to read this node and the children node under it, it cannot be right.
The input XML like:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<ns0:PO xmlns:ns0="http://HelloWorld.POSchema">
<PO_Number>16</PO_Number>
<Total>PO_Number1234</Total>
<PO_Number2>6</PO_Number2>
<PO_Number3>5</PO_Number3>
<PORoot>
<PORoot1>PORoot1</PORoot1>
<PORoot2>PORoot2</PORoot2>
<POChild>
<POChild1></POChild1>
<POChild2></POChild2>
</POChild>
</PORoot>
</ns0:PO>
And my XSLT code are below:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:ns0="http://HelloWorld.InvoiceSchema" xmlns:s0="http://HelloWorld.POSchema" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="PO">
<Invoice>
<Number><xsl:value-of select="PO_Number"/></Number>
</Invoice>
<xsl:element name="Invoice">
<xsl:element name="Number">
<xsl:value-of select="PO_Number"/>
</xsl:element>
<xsl:element name="TotalPrice">
<xsl:value-of select="Total"/>
</xsl:element>
<xsl:element name="Number2">
<xsl:value-of select="PO_Number2"/>
</xsl:element>
<xsl:element name="Number3">
<xsl:value-of select="PO_Number3"/>
</xsl:element>
<xsl:element name="InvoiceRoot">
<xsl:element name="InvoiceRoot1">
<xsl:value-of select="PORoot/PORoot1"/>
</xsl:element>
<xsl:element name="InvoiceRoot2">
<xsl:value-of select="PORoot/PORoot2"/>
</xsl:element>
<xsl:for-each select="PORoot/POChild/POChild1">
<xsl:choose>
<xsl:when test=". = null"></xsl:when>
<xsl:otherwise>
<InvoiceChild>
<InvoiceChild1>
<xsl:value-of select="POChild1"/>
</InvoiceChild1>
<InvoiceChild2>
<xsl:value-of select="POChild2"/>
</InvoiceChild2>
</InvoiceChild>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And the output XML cannot be viewed in IE since it said error.
So my questions are:
1. What is "ns"?
2. How to deal with the XML element with ns;
3. In the XSLT file, what are the attributes of the stylesheet mean?
Hopefully I have described my questions clear..
Thank you all in advance for any help!