The main question regarding XSL pattern matching

I just started messing around with XML and I have a question.

XML file:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<bucket version="Root Version 1A2B3C">
</bucket>

XSL FILE

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="bucket"> 
    <html>
       <body>
        <h3>
          <xsl:value-of select="@version"/>
        </h3>
      </body>
    </html>
  </xsl:template>
 </xsl:stylesheet>

I have questions regarding the third line of XSL. If i use

<xsl:template match="bucket">- Root Version 1A2B3Cprinted

<xsl:template match="/"> -

nothing is printed - I thought what the "/"root means. I understand that it should either print "1.0" ( <?xml version), or "Root version 1A2B3C" (bucket version)

Please let me know why it does not work.

thank

+3
source share
2 answers

/indicates a document node () is the entire document .

In the provided XML element bucketis the top element of the document. This is not the root node.

bucket - , . , / - node .

+2

http://www.w3.org/TR/xpath/#root-node

node . node , . node node. node , .

, ( http://www.w3.org/TR/xpath/#section-Introduction):

XPath , XML-, .

, document root / "" .

+2

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


All Articles