Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 18th, 2012, 01:13 AM
Authorized User
 
Join Date: Jul 2010
Posts: 74
Thanks: 23
Thanked 0 Times in 0 Posts
Question How to deal with the node with ns

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!

Last edited by JohnKiller; September 18th, 2012 at 01:16 AM..
 
Old September 18th, 2012, 04:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There are many tutorials on namespaces and XSLT: this one here

http://msdn.microsoft.com/en-us/library/ms950779.aspx

looks as if it might be around the right level for you.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
JohnKiller (September 18th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying data as a Parent Node with Left Node and Right Node Manoj Bisht Visual Basic 2008 Professionals 0 April 2nd, 2009 02:34 AM
changing two frams at the same time in NS nightshonour Javascript How-To 1 May 3rd, 2005 07:28 PM
SQL ns won't install jimbeam36 .NET Web Services 0 November 17th, 2004 03:33 AM
Works with IE5 and IE6, but not NS vincentms Beginning PHP 8 August 14th, 2003 06:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.