dp_20000310.py :  » XML » 4Suite » 4Suite-XML-1.0.2 » test » Xml » Xslt » Borrowed » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » XML » 4Suite 
4Suite » 4Suite XML 1.0.2 » test » Xml » Xslt » Borrowed » dp_20000310.py
#Namespace tracer from Pawson, David <DPawson@rnib.org.uk> on 10 March 2000, with a version using the namespace axis from David Carlisle.

from Xml.Xslt import test_harness

sheet_1 = """<?xml version='1.0'?>

<xsl:stylesheet 
   version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:ns-test="http://ns1.com"
   xmlns:ns1="http://ns1.com"
   xmlns:ns2="http://ns2.com"
   xmlns:long-namespace="http://ns3.com"
   exclude-result-prefixes="ns1 ns2 long-namespace"
>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="*">
  <!--<xsl:message><xsl:value-of select="name(.)"/></xsl:message>-->
  <tag>Namespace:<xsl:choose><xsl:when test="namespace-uri(.)"><xsl:value-of select="namespace-uri(.)"/>
      </xsl:when>
      <xsl:otherwise> Null namespace</xsl:otherwise>
    </xsl:choose>
  </tag>
  <tag>name: <xsl:value-of select="name(.)"/></tag>
  <tag>local-name: <xsl:value-of select="local-name(.)"/></tag>
  <tag>Content: <xsl:value-of select="text()"/></tag>
  <xsl:if test="./*"><xsl:apply-templates/></xsl:if>
</xsl:template>

</xsl:stylesheet>"""


sheet_2 = """<?xml version='1.0'?>

<xsl:stylesheet 
   version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:ns-test="http://ns1.com"
   xmlns:ns1="http://ns1.com"
   xmlns:ns2="http://ns2.com"
   xmlns:long-namespace="http://ns3.com"
   exclude-result-prefixes="ns1 ns2 long-namespace"
>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="*">
  <tag>Namespace:<xsl:choose><xsl:when test="namespace-uri(.)"><xsl:value-of select="namespace-uri(.)"/>
    </xsl:when>
    <xsl:otherwise> Null namespace</xsl:otherwise>
  </xsl:choose>

  <!-- namespaces are unordered, sort is needed for comparision only -->
    <xsl:for-each select="namespace::*">
      <xsl:sort select="name()"/>
      NS name: <xsl:value-of select="name(.)"/>
      NS value : <xsl:value-of select="."/>
    </xsl:for-each>

  </tag>
  <xsl:if test="./*"><xsl:apply-templates/></xsl:if>
</xsl:template>

</xsl:stylesheet>
"""


source_1="""<?xml version='1.0'?>

<!DOCTYPE ns1:ns-test [
<!ELEMENT ns1:ns-test (block)+>
<!ATTLIST ns-test  xmlns:ns1 CDATA #FIXED "http://ns1.com"
          
>
<!ELEMENT ns2:block (para)+>
<!ATTLIST block  xmlns:ns2 CDATA #FIXED "http://ns2.com"
>
<!ELEMENT para (#PCDATA)>
<!ATTLIST para id ID #IMPLIED
               another CDATA #IMPLIED>]>

<ns1:ns-test xmlns:ns1= "http://ns1.com">

  <block>
    <para>Para in block 1, main document namespace </para>
  </block>

  <ns2:block xmlns:ns2="http://ns2.com">
    <para>Para in block 2</para>
  </ns2:block>

    <ns3:block xmlns:ns3="http://ns3.com">
      <long:para xmlns:long="A long namespace uri">Para in block
3</long:para>
    </ns3:block>


</ns1:ns-test>"""


expected_1 = """<?xml version="1.0" encoding="UTF-8"?>
<tag>Namespace:http://ns1.com</tag>
<tag>name: ns1:ns-test</tag>
<tag>local-name: ns-test</tag>
<tag>Content: 

  </tag>

  <tag>Namespace: Null namespace</tag>
<tag>name: block</tag>
<tag>local-name: block</tag>
<tag>Content: 
    </tag>
    <tag>Namespace: Null namespace</tag>
<tag>name: para</tag>
<tag>local-name: para</tag>
<tag>Content: Para in block 1, main document namespace </tag>
  

  <tag>Namespace:http://ns2.com</tag>
<tag>name: ns2:block</tag>
<tag>local-name: block</tag>
<tag>Content: 
    </tag>
    <tag>Namespace: Null namespace</tag>
<tag>name: para</tag>
<tag>local-name: para</tag>
<tag>Content: Para in block 2</tag>
  

    <tag>Namespace:http://ns3.com</tag>
<tag>name: ns3:block</tag>
<tag>local-name: block</tag>
<tag>Content: 
      </tag>
      <tag>Namespace:A long namespace uri</tag>
<tag>name: long:para</tag>
<tag>local-name: para</tag>
<tag>Content: Para in block
3</tag>
    


"""


expected_2 = """<?xml version="1.0" encoding="UTF-8"?>
<tag>Namespace:http://ns1.com
      NS name: ns1
      NS value : http://ns1.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>

  <tag>Namespace: Null namespace
      NS name: ns1
      NS value : http://ns1.com
      NS name: ns2
      NS value : http://ns2.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>
    <tag>Namespace: Null namespace
      NS name: ns1
      NS value : http://ns1.com
      NS name: ns2
      NS value : http://ns2.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>
  

  <tag>Namespace:http://ns2.com
      NS name: ns1
      NS value : http://ns1.com
      NS name: ns2
      NS value : http://ns2.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>
    <tag>Namespace: Null namespace
      NS name: ns1
      NS value : http://ns1.com
      NS name: ns2
      NS value : http://ns2.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>
  

    <tag>Namespace:http://ns3.com
      NS name: ns1
      NS value : http://ns1.com
      NS name: ns3
      NS value : http://ns3.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>
      <tag>Namespace:A long namespace uri
      NS name: long
      NS value : A long namespace uri
      NS name: ns1
      NS value : http://ns1.com
      NS name: ns3
      NS value : http://ns3.com
      NS name: xml
      NS value : http://www.w3.org/XML/1998/namespace</tag>
    


"""

def Test(tester):
    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_1)
    test_harness.XsltTest(tester, source, [sheet], expected_1,
                          title='test 1')

    source = test_harness.FileInfo(string=source_1)
    sheet = test_harness.FileInfo(string=sheet_2)
    test_harness.XsltTest(tester, source, [sheet], expected_2,
                          title='test 2')
    return
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.