Exemple #1
0
def test_key_2():
    """keys scoped to context document"""
    _run_text(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">

  <xsl:output method='text'/>

  <xsl:key name='name' match='*' use='name()'/>

  <xsl:template match="/">
    <xsl:for-each select=".">
      Entries from keys: <xsl:value-of select="count(key('name', 'ENTRY'))"/>
      Template from keys: <xsl:value-of select="count(key('name', 'xsl:template'))"/>
    </xsl:for-each>
    <xsl:for-each select="document('')">
      Entries from keys: <xsl:value-of select="count(key('name', 'ENTRY'))"/>
      Template from keys: <xsl:value-of select="count(key('name', 'xsl:template'))"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
""",
              expected="""
      Entries from keys: 3
      Template from keys: 0
      Entries from keys: 0
      Template from keys: 1""")
Exemple #2
0
def test_key_3():
    """keys using patterns of form `ns:*`"""
    _run_text(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:output method="text"/>

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

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

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

</xsl:stylesheet>
""",
              expected="""
    Entries from key 1: 1
    Entries from key 2: 1""")
Exemple #3
0
def test_key_6():
    """included keys (test_key_6)"""
    _run_text(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">

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

  <xsl:output method="text"/>

  <!--
    creates a silly key which indexes all ENTRY elements in the doc
    as 'pa' just to be different from the key in the import with the
    same name
    -->
  <xsl:key name='k1' match='ENTRY' use="'pa'"/>

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

</xsl:stylesheet>
""",
              expected="""
    Entries from key 1: 3
    Entries from key 2: 1""")
Exemple #4
0
def test_key_2():
    """keys scoped to context document"""
    _run_text(
        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">

  <xsl:output method='text'/>

  <xsl:key name='name' match='*' use='name()'/>

  <xsl:template match="/">
    <xsl:for-each select=".">
      Entries from keys: <xsl:value-of select="count(key('name', 'ENTRY'))"/>
      Template from keys: <xsl:value-of select="count(key('name', 'xsl:template'))"/>
    </xsl:for-each>
    <xsl:for-each select="document('')">
      Entries from keys: <xsl:value-of select="count(key('name', 'ENTRY'))"/>
      Template from keys: <xsl:value-of select="count(key('name', 'xsl:template'))"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>
""",
        expected = """
      Entries from keys: 3
      Template from keys: 0
      Entries from keys: 0
      Template from keys: 1"""
        )
Exemple #5
0
def test_key_6():
    """included keys (test_key_6)"""
    _run_text(
        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">

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

  <xsl:output method="text"/>

  <!--
    creates a silly key which indexes all ENTRY elements in the doc
    as 'pa' just to be different from the key in the import with the
    same name
    -->
  <xsl:key name='k1' match='ENTRY' use="'pa'"/>

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

</xsl:stylesheet>
""",
        expected = """
    Entries from key 1: 3
    Entries from key 2: 1""")
Exemple #6
0
def test_key_5():
    """included keys (test_key_5)"""
    _run_text(
        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">

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

  <xsl:output method="text"/>

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

</xsl:stylesheet>
""",
        expected = """
    Entries from key 1: 1
    Entries from key 2: 1"""
        )
Exemple #7
0
def test_key_3():
    """keys using patterns of form `ns:*`"""
    _run_text(
        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:output method="text"/>

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

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

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

</xsl:stylesheet>
""",
        expected = """
    Entries from key 1: 1
    Entries from key 2: 1"""
        )
Exemple #8
0
def test_key_5():
    """included keys (test_key_5)"""
    _run_text(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">

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

  <xsl:output method="text"/>

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

</xsl:stylesheet>
""",
              expected="""
    Entries from key 1: 1
    Entries from key 2: 1""")