예제 #1
0
def test_copy_of_2():
    """copy external document"""
    _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
             transform_uri="file:" + module_dirname + "/test_copy_of.py",
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:copy-of select="document('svgeg.svg')"/>
</xsl:template>

</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" height="10cm" width="10cm" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" zoomAndPan="magnify" viewBox="0 0 800 800" contentScriptType="text/ecmascript">
  <desc content="structured text">SVG Sample for SunWorld Article</desc>

  <style xml:space="preserve" type="text/css">
    .Lagos { fill: white; stroke: green; stroke-width: 30 }
    .ViaAppia { fill: none; stroke: black; stroke-width: 10 }
    .OrthoLogos { font-size: 32; font-family: helvetica }
  </style>

  <ellipse style="fill: brown; stroke: yellow; stroke-width: 10" rx="250" transform="translate(500 200)" ry="100"/>

  <polygon points="350,75 379,161 469,161 397,215 423,301 350,250 277,                    301 303,215 231,161 321,161" transform="translate(100 200) rotate(45)" class="Lagos"/>

  <text y="400" x="400" class="OrthoLogos">TO KALON</text>

  <path d="M500,600 C500,500 650,500 650,600                             S800,700 800,600" class="ViaAppia"/>
</svg>""")
예제 #2
0
def test_apply_imports_error_1():
    """xsl:apply-imports with xsl:param children"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="test-apply-imports-2.xslt"/>

  <xsl:template match="doc">
    <body>
      <xsl:apply-imports>
        <xsl:with-param name="border-style" select="'dotted'"/>
      </xsl:apply-imports>
    </body>
  </xsl:template>

  <xsl:template match="*">
    <unknown-element><xsl:value-of select="name()"/></unknown-element>
  </xsl:template>

</xsl:stylesheet>
""",
                 expected=None,
                 transform_uri=module_uri)
    except XsltError, err:
        assert err.code == XsltError.ILLEGAL_ELEMENT_CHILD
예제 #3
0
def test_basics_5():
    _run_xml("<dummy/>",
             """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

  <xsl:param name='override' select='"abc"'/>
  <xsl:param name='list' select='foo'/>

  <xsl:template match="/">
    <doc>
      <overridden><xsl:value-of select='$override'/></overridden>
      <list><xsl:apply-templates select="$list"/></list>
    </doc>
  </xsl:template>

  <xsl:template match="text()">
    <item><xsl:value-of select="."/></item>
  </xsl:template>

</xsl:stylesheet>
""",
             """<?xml version='1.0' encoding='UTF-8'?>
<doc><overridden>xyz</overridden><list><item>a</item><item>b</item><item>c</item></list></doc>""",
             parameters={
                 'override': 'xyz',
                 'list': ('a', 'b', 'c')
             })
예제 #4
0
def test_fallback_error_4():
    """non-1.0 literal result element without fallback"""
    try:
        _run_xml(
            source_xml = FALLBACK_SOURCE_XML,
            transform_uri = TRANSFORM_URI,
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <!--
      literal result element version != 1.0;
      fallback must be performed;
      since no fallback child, error must be signaled.
    -->
    <result xsl:version="3.0">
      <xsl:perform-magic/>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except XsltError, err:
        assert err.code == XsltError.FWD_COMPAT_WITHOUT_FALLBACK
예제 #5
0
파일: test_if.py 프로젝트: abed-hawa/amara
def test_if_2():
    """test text and element children of `xsl:if`"""
    _run_xml(
        source_xml = """<?xml version="1.0"?><dummy/>""",
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <boo>
      <!-- true -->
      <xsl:if test='/'>
        ( <true/> )
      </xsl:if>
      <!-- false -->
      <xsl:if test='/..'>
        ( <false/> )
      </xsl:if>
    </boo>
  </xsl:template>

</xsl:stylesheet>
""",
    expected = """<?xml version="1.0" encoding="UTF-8"?>
<boo>\n        ( <true/> )\n      </boo>"""
        )
예제 #6
0
def test_elem_attr_2():
    """`xsl:element` with namespaces"""
    _run_xml(
        source_xml = '<?xml version="1.0"?><dummy/>',
        transform_xml = """<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

  <xsl:template match="/">
    <result>
      <!-- should be in explicitly specified namespace --> 
      <xsl:element name="xse-ns" namespace="http://foo/bar"/>
      <xsl:element name="xse-empty-ns" namespace=""/>
      <!-- should be in default namespace (empty) -->
      <xsl:element name="xse"/>
      <lre-ns xmlns="http://stuff">
        <!-- should be in explicitly specified namespace -->   
        <xsl:element name="xse-ns" namespace="http://foo/bar"/>
        <xsl:element name="xse-empty-ns" namespace=""/>
        <!-- should be in http://stuff namespace -->
        <xsl:element name="xse"/>
      </lre-ns>
    </result>
  </xsl:template>

</xsl:transform>""",
        expected = """<?xml version='1.0' encoding='UTF-8'?>
<result><xse-ns xmlns='http://foo/bar'/><xse-empty-ns/><xse/><lre-ns xmlns='http://stuff'><xse-ns xmlns='http://foo/bar'/><xse-empty-ns xmlns=''/><xse/></lre-ns></result>"""
        )
예제 #7
0
파일: test_key.py 프로젝트: abed-hawa/amara
def test_key_error_1():
    """keys using patterns of form `ns:*`"""
    try:
        _run_xml(
            source_xml = FILE_SOURCE_XML,
            source_uri = FILE_URI,
            transform_uri = TRANSFORM_URI,
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:x="http://spam.com"
>

  <xsl:import href="test-key-import-error.xslt"/>

  <x:grail id="ein"/>
  <x:grail id="zwo"/>
  <x:knicht id="drei"/>
  <x:knicht id="vier"/>

  <xsl:template match="/">
    Entries from key 1: <xsl:value-of select="count(key('k1', 'pa'))"/>
    <xsl:for-each select="document('')">
    Entries from key 2: <xsl:copy-of select="count(key('k2', 'drei'))"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
""",
            expected = None)
    except XsltError, err:
        assert err.code == XsltError.UNDEFINED_PREFIX
예제 #8
0
파일: test_key.py 프로젝트: abed-hawa/amara
def test_key_7():
    """included keys (test_key_7)"""
    _run_xml(
        source_xml = FILE_SOURCE_XML,
        source_uri = FILE_URI,
        transform_uri = TRANSFORM_URI,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:x="http://spam.com/x"
>

  <xsl:output method="xml"/>

  <xsl:key name='k1' match='x:*' use='local-name()'/>
  <xsl:key name='k1' match='x:*' use='@id'/>

  <x:vier id="ein"/>
  <x:drei id="zwo"/>
  <x:zwo id="drei"/>
  <x:ein id="vier"/>

  <xsl:template match="/">
    <result>
      <xsl:for-each select="document('')">
        <xsl:copy-of select="key('k1', 'drei')"/>
      </xsl:for-each>
    </result>
  </xsl:template>

</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:x="http://spam.com/x"><x:drei id="zwo"/><x:zwo id="drei"/></result>"""
        )
예제 #9
0
def test_key_error_1():
    """keys using patterns of form `ns:*`"""
    try:
        _run_xml(source_xml=FILE_SOURCE_XML,
                 source_uri=FILE_URI,
                 transform_uri=TRANSFORM_URI,
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:x="http://spam.com"
>

  <xsl:import href="test-key-import-error.xslt"/>

  <x:grail id="ein"/>
  <x:grail id="zwo"/>
  <x:knicht id="drei"/>
  <x:knicht id="vier"/>

  <xsl:template match="/">
    Entries from key 1: <xsl:value-of select="count(key('k1', 'pa'))"/>
    <xsl:for-each select="document('')">
    Entries from key 2: <xsl:copy-of select="count(key('k2', 'drei'))"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
""",
                 expected=None)
    except XsltError, err:
        assert err.code == XsltError.UNDEFINED_PREFIX
예제 #10
0
def test_key_7():
    """included keys (test_key_7)"""
    _run_xml(source_xml=FILE_SOURCE_XML,
             source_uri=FILE_URI,
             transform_uri=TRANSFORM_URI,
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:x="http://spam.com/x"
>

  <xsl:output method="xml"/>

  <xsl:key name='k1' match='x:*' use='local-name()'/>
  <xsl:key name='k1' match='x:*' use='@id'/>

  <x:vier id="ein"/>
  <x:drei id="zwo"/>
  <x:zwo id="drei"/>
  <x:ein id="vier"/>

  <xsl:template match="/">
    <result>
      <xsl:for-each select="document('')">
        <xsl:copy-of select="key('k1', 'drei')"/>
      </xsl:for-each>
    </result>
  </xsl:template>

</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:x="http://spam.com/x"><x:drei id="zwo"/><x:zwo id="drei"/></result>"""
             )
예제 #11
0
def test_fallback_5():
    """uninstantiated non-1.0 literal result element"""
    _run_xml(
        source_xml = FALLBACK_SOURCE_XML,
        source_uri = "file:xslt/test_fallback.py",
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <!--
      literal result element version != 1.0;
      element is not instantiated;
      no error must be signaled.
    -->
    <result xsl:version="3.0">
      <xsl:choose>
        <xsl:when test="false()">
          <xsl:perform-magic>We do magic<xsl:fallback>Sorry, we don't do magic</xsl:fallback></xsl:perform-magic>
        </xsl:when>
        <xsl:otherwise>hello world</xsl:otherwise>
      </xsl:choose>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result>hello world</result>""")
예제 #12
0
def test_basics_5():
    _run_xml(
        "<dummy/>",
        """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

  <xsl:param name='override' select='"abc"'/>
  <xsl:param name='list' select='foo'/>

  <xsl:template match="/">
    <doc>
      <overridden><xsl:value-of select='$override'/></overridden>
      <list><xsl:apply-templates select="$list"/></list>
    </doc>
  </xsl:template>

  <xsl:template match="text()">
    <item><xsl:value-of select="."/></item>
  </xsl:template>

</xsl:stylesheet>
""",
        """<?xml version='1.0' encoding='UTF-8'?>
<doc><overridden>xyz</overridden><list><item>a</item><item>b</item><item>c</item></list></doc>""",
        parameters={"override": "xyz", "list": ("a", "b", "c")},
    )
예제 #13
0
def test_basics_8():
    _run_xml(
        '<div><hr noshade="noshade"/></div>',
        OUTPUT_TEMPLATE % 'method="xml"',
        """<?xml version="1.0" encoding="UTF-8"?>
<div><hr noshade="noshade"/></div>""",
    )
예제 #14
0
def test_apply_templates_4():
    """`xsl:apply-templates` using `xsl:sort` and `xsl:with-param`"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <docelem>
      <xsl:apply-templates/>
    </docelem>
  </xsl:template>
  <xsl:template match='data'>
    <xsl:apply-templates>
      <xsl:sort/>
      <xsl:with-param name='foo' select='1'/>
    </xsl:apply-templates>
  </xsl:template>
  <xsl:template match='text()'/>
  <xsl:template match='item'>
    <xsl:param name='foo'/>
    <xsl:value-of select='concat($foo,.)'/>
  </xsl:template>
</xsl:stylesheet>
""",
    expected = """<?xml version="1.0" encoding="UTF-8"?>
<docelem>""" + "1a"*5 + "1b"*5 + "1c"*5 + "1d"*5 + "</docelem>")
예제 #15
0
def test_copy_of_2():
    """copy external document"""
    _run_xml(
        source_xml = """<?xml version="1.0"?><dummy/>""",
        transform_uri = "file:" + module_dirname + "/test_copy_of.py",
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:copy-of select="document('svgeg.svg')"/>
</xsl:template>

</xsl:stylesheet>
""",
    expected = """<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" height="10cm" width="10cm" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" zoomAndPan="magnify" viewBox="0 0 800 800" contentScriptType="text/ecmascript">
  <desc content="structured text">SVG Sample for SunWorld Article</desc>

  <style xml:space="preserve" type="text/css">
    .Lagos { fill: white; stroke: green; stroke-width: 30 }
    .ViaAppia { fill: none; stroke: black; stroke-width: 10 }
    .OrthoLogos { font-size: 32; font-family: helvetica }
  </style>

  <ellipse style="fill: brown; stroke: yellow; stroke-width: 10" rx="250" transform="translate(500 200)" ry="100"/>

  <polygon points="350,75 379,161 469,161 397,215 423,301 350,250 277,                    301 303,215 231,161 321,161" transform="translate(100 200) rotate(45)" class="Lagos"/>

  <text y="400" x="400" class="OrthoLogos">TO KALON</text>

  <path d="M500,600 C500,500 650,500 650,600                             S800,700 800,600" class="ViaAppia"/>
</svg>""")
예제 #16
0
def test_basics_6():
    'Basic output parameter test, 1'
    _run_xml(
        '<div><hr noshade="noshade"/></div>',
        OUTPUT_TEMPLATE % 'method="xml" indent="yes"',
        """<?xml version="1.0" encoding="UTF-8"?>
<div>
  <hr noshade="noshade"/>
</div>""")
예제 #17
0
파일: test_if.py 프로젝트: abed-hawa/amara
def test_if_1():
    """`xsl:if`"""
    _run_xml(
        source_xml = inputsource(FILE("addr_book1.xml")),
        transform_uri = "file:xslt/test_if.py",
        transform_xml = """<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:strip-space elements='*'/>

  <xsl:template match="/">
    <HTML>
    <HEAD><TITLE>Address Book</TITLE>
    </HEAD>
    <BODY>
    <TABLE><xsl:apply-templates/></TABLE>
    </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="ENTRY">
        <xsl:element name='TR'>
        <xsl:apply-templates select='NAME'/>
        </xsl:element>
        <xsl:if test='not(position()=last())'><HR/></xsl:if>
  </xsl:template>

  <xsl:template match="NAME">
    <xsl:element name='TD'>
    <xsl:attribute name='ALIGN'>CENTER</xsl:attribute>
      <B><xsl:apply-templates/></B>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>
""",
    expected = """<HTML>
  <HEAD>
    <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'>
    <TITLE>Address Book</TITLE>
  </HEAD>
  <BODY>
    <TABLE>
      <TR>
        <TD ALIGN='CENTER'><B>Pieter Aaron</B></TD>
      </TR>
      <HR>
      <TR>
        <TD ALIGN='CENTER'><B>Emeka Ndubuisi</B></TD>
      </TR>
      <HR>
      <TR>
        <TD ALIGN='CENTER'><B>Vasia Zhugenev</B></TD>
      </TR>
    </TABLE>
  </BODY>
</HTML>""")
예제 #18
0
파일: test_if.py 프로젝트: mredar/amara
def test_if_1():
    """`xsl:if`"""
    _run_xml(source_xml=inputsource(FILE("addr_book1.xml")),
             transform_uri="file:xslt/test_if.py",
             transform_xml="""<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:strip-space elements='*'/>

  <xsl:template match="/">
    <HTML>
    <HEAD><TITLE>Address Book</TITLE>
    </HEAD>
    <BODY>
    <TABLE><xsl:apply-templates/></TABLE>
    </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="ENTRY">
        <xsl:element name='TR'>
        <xsl:apply-templates select='NAME'/>
        </xsl:element>
        <xsl:if test='not(position()=last())'><HR/></xsl:if>
  </xsl:template>

  <xsl:template match="NAME">
    <xsl:element name='TD'>
    <xsl:attribute name='ALIGN'>CENTER</xsl:attribute>
      <B><xsl:apply-templates/></B>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>
""",
             expected="""<HTML>
  <HEAD>
    <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'>
    <TITLE>Address Book</TITLE>
  </HEAD>
  <BODY>
    <TABLE>
      <TR>
        <TD ALIGN='CENTER'><B>Pieter Aaron</B></TD>
      </TR>
      <HR>
      <TR>
        <TD ALIGN='CENTER'><B>Emeka Ndubuisi</B></TD>
      </TR>
      <HR>
      <TR>
        <TD ALIGN='CENTER'><B>Vasia Zhugenev</B></TD>
      </TR>
    </TABLE>
  </BODY>
</HTML>""")
예제 #19
0
def test_basics_6():
    "Basic output parameter test, 1"
    _run_xml(
        '<div><hr noshade="noshade"/></div>',
        OUTPUT_TEMPLATE % 'method="xml" indent="yes"',
        """<?xml version="1.0" encoding="UTF-8"?>
<div>
  <hr noshade="noshade"/>
</div>""",
    )
예제 #20
0
def test_attribute_error_2():
    """adding attribute to non-element"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <xsl:attribute name="foo">bar</xsl:attribute>
  </xsl:template>
</xsl:stylesheet>
""",
                 expected=None)
    except WriterError, err:
        assert err.code == WriterError.ATTRIBUTE_ADDED_TO_NON_ELEMENT
예제 #21
0
def test_attribute_2():
    """`xsl:attribute` as child of literal result element"""
    _run_xml(source_xml=SOURCE_XML,
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="foo">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<result foo="bar"/>""")
예제 #22
0
def test_attribute_2():
    """`xsl:attribute` as child of literal result element"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="foo">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result foo="bar"/>""")
예제 #23
0
def test_attribute_5():
    """adding attributes with the same expanded-name"""
    _run_xml(source_xml=SOURCE_XML,
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result foo="bar">
      <!-- duplicate attrs override previous -->
      <xsl:attribute name="foo">baz</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<result foo="baz"/>""")
예제 #24
0
def test_attribute_error_2():
    """adding attribute to non-element"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><dummy/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <xsl:attribute name="foo">bar</xsl:attribute>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except WriterError, err:
        assert err.code == WriterError.ATTRIBUTE_ADDED_TO_NON_ELEMENT
예제 #25
0
def test_attribute_10():
    """substitution of xmlns prefix in attribute name"""
    _run_xml(source_xml=SOURCE_XML,
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result>
      <!-- if an attribute prefix would be xmlns, it must be changed to something else -->
      <xsl:attribute name="xmlns:foo" namespace="http://example.com/">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:%(prefix0)s="http://example.com/" %(prefix0)s:foo="bar"/>""" %
             {'prefix0': PREFIX_TEMPLATE % 0})
예제 #26
0
def test_attribute_error_4():
    """illegal attribute name ("xmlns")"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="xmlns">http://example.com/</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
                 expected=None)
    except XsltError, err:
        assert err.code == XsltError.BAD_ATTRIBUTE_NAME
예제 #27
0
def test_attribute_error_5():
    """illegal attribute name (non-QName)"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="#invalid">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
                 expected=None)
    except XsltError, err:
        assert err.code == XsltError.INVALID_QNAME_ATTR
예제 #28
0
def test_attribute_3():
    """`xsl:attribute` with namespace"""
    _run_xml(source_xml=SOURCE_XML,
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="foo" namespace="http://example.com/spam">bar</xsl:attribute>
      <xsl:attribute name="y:foo" namespace="http://example.com/eggs">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:%(prefix0)s="http://example.com/spam" xmlns:y="http://example.com/eggs" %(prefix0)s:foo="bar" y:foo="bar"/>"""
             % {'prefix0': PREFIX_TEMPLATE % 0})
예제 #29
0
def test_apply_templates_6():
    """`xsl:apply-templates` with select of attributes"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <docelem>
      <xsl:apply-templates select='data/item/@in'/>
    </docelem>
  </xsl:template>
  <xsl:template match='@*[. = "1"]'>!</xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<docelem>""" + "!!"*5 + "</docelem>")
예제 #30
0
def test_attribute_error_3():
    """creating non-text during xsl:attribute instantiation"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <xsl:attribute name="foo">
      <xsl:comment>no-no</xsl:comment>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>
""",
                 expected=None)
    except XsltError, err:
        assert err.code == XsltError.NONTEXT_IN_ATTRIBUTE
예제 #31
0
def test_attribute_9():
    """serialization of linefeed in attribute value"""
    _run_xml(source_xml=SOURCE_XML,
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result>
      <!-- linefeed must be serialized as &#10; -->
      <xsl:attribute name="a">x
y</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<result a="x&#10;y"/>""")
예제 #32
0
def test_copy_of_1():
    """copy element and contents"""
    _run_xml(source_xml="""<?xml version="1.0"?>
<foo>Embedded <html><a href='link'>go</a>.</html></foo>""",
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="html">
  <xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="*">
  <xsl:apply-templates select="*"/>
</xsl:template>
</xsl:stylesheet>
""",
             expected="""<html><a href='link'>go</a>.</html>""")
예제 #33
0
def test_attribute_5():
    """adding attributes with the same expanded-name"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result foo="bar">
      <!-- duplicate attrs override previous -->
      <xsl:attribute name="foo">baz</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result foo="baz"/>""")
예제 #34
0
def test_call_template_1():
    """`xsl:call-template"""
    _run_xml(
        source_xml = """<?xml version="1.0"?>
<data>
 <item>b</item>
 <item>a</item>
 <item>d</item>
 <item>c</item>
</data>
""",
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<root>
  <xsl:apply-templates/>
</root>
</xsl:template>

<xsl:template name="do-the-rest">
  <xsl:param name="start"/>
  <xsl:param name="count"/>
  <tr>
  <xsl:for-each select="item[position()&gt;=$start and position()&lt;$start+$count]">
    <td>
    <xsl:value-of select="."/>
    </td>
  </xsl:for-each>
  </tr>
  <xsl:if test="$start + $count - 1 &lt; count(child::item)">
  <xsl:call-template name="do-the-rest">
    <xsl:with-param name="start" select="$start + $count"/>
    <xsl:with-param name="count" select="$count"/>
  </xsl:call-template>
  </xsl:if>  
</xsl:template>

<xsl:template match="data">
  <xsl:call-template name="do-the-rest">
    <xsl:with-param name="start" select="1"/>
    <xsl:with-param name="count" select="2"/>
  </xsl:call-template>
</xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version='1.0' encoding='UTF-8'?>
<root><tr><td>b</td><td>a</td></tr><tr><td>d</td><td>c</td></tr></root>""")
예제 #35
0
def test_attribute_3():
    """`xsl:attribute` with namespace"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="foo" namespace="http://example.com/spam">bar</xsl:attribute>
      <xsl:attribute name="y:foo" namespace="http://example.com/eggs">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:%(prefix0)s="http://example.com/spam" xmlns:y="http://example.com/eggs" %(prefix0)s:foo="bar" y:foo="bar"/>""" % {
    'prefix0' : PREFIX_TEMPLATE % 0})
예제 #36
0
def test_call_template_1():
    """`xsl:call-template"""
    _run_xml(source_xml="""<?xml version="1.0"?>
<data>
 <item>b</item>
 <item>a</item>
 <item>d</item>
 <item>c</item>
</data>
""",
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<root>
  <xsl:apply-templates/>
</root>
</xsl:template>

<xsl:template name="do-the-rest">
  <xsl:param name="start"/>
  <xsl:param name="count"/>
  <tr>
  <xsl:for-each select="item[position()&gt;=$start and position()&lt;$start+$count]">
    <td>
    <xsl:value-of select="."/>
    </td>
  </xsl:for-each>
  </tr>
  <xsl:if test="$start + $count - 1 &lt; count(child::item)">
  <xsl:call-template name="do-the-rest">
    <xsl:with-param name="start" select="$start + $count"/>
    <xsl:with-param name="count" select="$count"/>
  </xsl:call-template>
  </xsl:if>  
</xsl:template>

<xsl:template match="data">
  <xsl:call-template name="do-the-rest">
    <xsl:with-param name="start" select="1"/>
    <xsl:with-param name="count" select="2"/>
  </xsl:call-template>
</xsl:template>
</xsl:stylesheet>
""",
             expected="""<?xml version='1.0' encoding='UTF-8'?>
<root><tr><td>b</td><td>a</td></tr><tr><td>d</td><td>c</td></tr></root>""")
예제 #37
0
def test_attribute_error_5():
    """illegal attribute name (non-QName)"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><dummy/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="#invalid">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except XsltError, err:
        assert err.code == XsltError.INVALID_QNAME_ATTR
예제 #38
0
def test_attribute_error_3():
    """creating non-text during xsl:attribute instantiation"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><dummy/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <xsl:attribute name="foo">
      <xsl:comment>no-no</xsl:comment>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except XsltError, err:
        assert err.code == XsltError.NONTEXT_IN_ATTRIBUTE
예제 #39
0
def test_apply_imports_1():
    _run_xml(source_xml='<example>This is an example</example>',
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="test-apply-imports-1.xslt"/>

  <xsl:template match="example">
    <div style="border: solid red">
      <xsl:apply-imports/>
    </div>
  </xsl:template>

</xsl:stylesheet>""",
             expected="""<?xml version='1.0' encoding='UTF-8'?>
<div style="border: solid red"><pre>This is an example</pre></div>""",
             transform_uri=module_uri)
예제 #40
0
def test_attribute_error_6():
    """illegal namespace-uri"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="foo" namespace="http://www.w3.org/XML/1998/namespace">bar</xsl:attribute>
      <xsl:attribute name="spam" namespace="http://www.w3.org/2000/xmlns/">eggs</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
                 expected=None)
    except XsltError, err:
        assert err.code == XsltError.INVALID_NS_URIREF_ATTR
예제 #41
0
def test_attribute_error_4():
    """illegal attribute name ("xmlns")"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><dummy/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="xmlns">http://example.com/</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except XsltError, err:
        assert err.code == XsltError.BAD_ATTRIBUTE_NAME
예제 #42
0
def test_attribute_error_1():
    """adding attribute ater non-attributes"""
    try:
        _run_xml(source_xml="""<?xml version="1.0"?><dummy/>""",
                 transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:text>Hello World</xsl:text>
      <xsl:attribute name="foo">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
                 expected=None)
    except WriterError, err:
        assert err.code == WriterError.ATTRIBUTE_ADDED_TOO_LATE
예제 #43
0
def test_attribute_error_6():
    """illegal namespace-uri"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><dummy/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:attribute name="foo" namespace="http://www.w3.org/XML/1998/namespace">bar</xsl:attribute>
      <xsl:attribute name="spam" namespace="http://www.w3.org/2000/xmlns/">eggs</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except XsltError, err:
        assert err.code == XsltError.INVALID_NS_URIREF_ATTR
예제 #44
0
def test_attribute_9():
    """serialization of linefeed in attribute value"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result>
      <!-- linefeed must be serialized as &#10; -->
      <xsl:attribute name="a">x
y</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result a="x&#10;y"/>"""
        )
예제 #45
0
def test_attribute_10():
    """substitution of xmlns prefix in attribute name"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <result>
      <!-- if an attribute prefix would be xmlns, it must be changed to something else -->
      <xsl:attribute name="xmlns:foo" namespace="http://example.com/">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:%(prefix0)s="http://example.com/" %(prefix0)s:foo="bar"/>""" % {
            'prefix0': PREFIX_TEMPLATE % 0}
        )
예제 #46
0
def test_copy_of_1():
    """copy element and contents"""
    _run_xml(
        source_xml = """<?xml version="1.0"?>
<foo>Embedded <html><a href='link'>go</a>.</html></foo>""",
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="html">
  <xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="*">
  <xsl:apply-templates select="*"/>
</xsl:template>
</xsl:stylesheet>
""",
        expected = """<html><a href='link'>go</a>.</html>"""
        )
예제 #47
0
def test_attribute_error_1():
    """adding attribute ater non-attributes"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><dummy/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <result>
      <xsl:text>Hello World</xsl:text>
      <xsl:attribute name="foo">bar</xsl:attribute>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
            expected = None)
    except WriterError, err:
        assert err.code == WriterError.ATTRIBUTE_ADDED_TOO_LATE
예제 #48
0
def test_apply_templates_5():
    """`xsl:apply-templates` with select"""
    _run_xml(
        source_xml = SOURCE_XML,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match='/'>
    <docelem>
      <xsl:apply-templates select='data/item[@in]'/>
    </docelem>
  </xsl:template>
  <xsl:template match='item'>
    <xsl:value-of select='.'/>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<docelem>""" + "ac"*5 + "</docelem>")
예제 #49
0
def test_literals_1():
    _run_xml(source_xml="""<customer id="uo">Uche Ogbuji</customer>""",
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="customer">
    <wrapper>
    <customer id="{@id}" xmlns="http://spam.com">
      <xsl:element name="{substring-before(., ' ')}" namespace="http://eggs.com">Eggs</xsl:element>
      <name><xsl:value-of select="."/></name>
    </customer>
    </wrapper>
  </xsl:template>

</xsl:stylesheet>
""",
             expected="""<?xml version='1.0' encoding='UTF-8'?>
<wrapper><customer id='uo' xmlns='http://spam.com'><Uche xmlns='http://eggs.com'>Eggs</Uche><name>Uche Ogbuji</name></customer></wrapper>"""
             )
예제 #50
0
def test_apply_templates_error_2():
    """xsl:apply-templates with invalid select expression"""
    try:
        _run_xml(
            source_xml = """<?xml version="1.0"?><foo/>""",
            transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

  <xsl:template match="/">
    <xsl:apply-templates select="'why is a string here?'"/>
  </xsl:template>

</xsl:stylesheet>
""",
            expected = None)
    except TypeError:
        pass
예제 #51
0
def test_fallback_1():
    """1.0 stylesheet with non-1.0 top-level element"""
    _run_xml(
        source_xml = FALLBACK_SOURCE_XML,
        transform_uri = TRANSFORM_URI,
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <greeting xsl:version="3.0">hello</greeting>
  <xsl:template match="/">
    <result>
      <xsl:value-of select="document('')/*/greeting"/>
    </result>
  </xsl:template>
</xsl:stylesheet>
""",
        expected = """<?xml version="1.0" encoding="UTF-8"?>
<result>hello</result>"""
        )
예제 #52
0
def test_copy_1():
    """`xsl:copy`"""
    _run_xml(source_xml="""<?xml version="1.0"?>
<foo a="1" b="2">
  <?foobar baz?>
  <bar/>
</foo>
""",
             transform_xml="""<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="foo">
  <xsl:copy/>
</xsl:template>

</xsl:stylesheet>
""",
             expected="""<?xml version="1.0" encoding="UTF-8"?>
<foo/>""")
예제 #53
0
def test_copy_2():
    """identity transform"""
    _run_xml(
        source_xml = inputsource(os.path.join(module_dirname, 'addr_book1.xml')),
        source_uri = "file:" + module_dirname + "/addr_book1.xml",
        transform_xml = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
""",
        expected ="""<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="addr_book1.xsl" type="text/xml"?><ADDRBOOK>
    <ENTRY ID='pa'>
        <NAME>Pieter Aaron</NAME>
        <ADDRESS>404 Error Way</ADDRESS>
        <PHONENUM DESC='Work'>404-555-1234</PHONENUM>
        <PHONENUM DESC='Fax'>404-555-4321</PHONENUM>
        <PHONENUM DESC='Pager'>404-555-5555</PHONENUM>
        <EMAIL>[email protected]</EMAIL>
    </ENTRY>
    <ENTRY ID='en'>
        <NAME>Emeka Ndubuisi</NAME>
        <ADDRESS>42 Spam Blvd</ADDRESS>
        <PHONENUM DESC='Work'>767-555-7676</PHONENUM>
        <PHONENUM DESC='Fax'>767-555-7642</PHONENUM>
        <PHONENUM DESC='Pager'>800-SKY-PAGEx767676</PHONENUM>
        <EMAIL>[email protected]</EMAIL>
    </ENTRY>
    <ENTRY ID='vz'>
        <NAME>Vasia Zhugenev</NAME>
        <ADDRESS>2000 Disaster Plaza</ADDRESS>
        <PHONENUM DESC='Work'>000-987-6543</PHONENUM>
        <PHONENUM DESC='Cell'>000-000-0000</PHONENUM>
        <EMAIL>[email protected]</EMAIL>
    </ENTRY>
</ADDRBOOK>""")