XSLT document function ('') does not work

As I understand from the documents, an XSLT function document () with an empty string as a parameter should read the current XSLT document. But the following code does not work:

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <state>test2</state>
   <xsl:template match="/">
      test1
      <xsl:value-of select="document('')/*/state"/>
    </xsl:template>
   </xsl:stylesheet>

When I apply this XSLT to some XML (for example, for example), I only have "test1" as the output. Why line

 <xsl:value-of select="document('')/*/state"/>

doesn't print "test2"?

+3
source share
2 answers

('') , XML-, URI URI , (''). , , , URI . , , URI . , XSLT , (, DOM), , URI. , JSXP StreamSource setSystemId(), URI .

+9

, :

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:my="http://localhost"
    exclude-result-prefixes="my">
    <xsl:output method="text"/>

    <my:state>test2</my:state>

    <xsl:template match="/">
        <xsl:text>test1</xsl:text>
        <xsl:value-of select="document('')/*/my:state"/>
    </xsl:template>
</xsl:stylesheet>

Ouput:

test1test2

:

URI, XSLT URI , . XSLT-.

+1

Source: https://habr.com/ru/post/1788130/


All Articles