Xsl: pattern matching attribute: as related to the default namespace

I found a peculiar difference in the behavior of xslt when the root element has a default namespace attribute, and not the one when it does not.
I wonder why this is happening.

XML input

<root>
    <content>xxx</content>
</root>

When does the following conversion apply

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <root>
            <xsl:apply-templates/>
        </root>
    </xsl:template>

    <xsl:template match="content">
        <w>x</w>
    </xsl:template>

</xsl:stylesheet>

result - expected

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <w>x</w>
</root>

But when the same conversion applies to

<root xmlns="http://test.com">
    <content>xxx</content>
</root>

the result is different and based on the use of only default templates (which effectively print the text node value "xxx"):

<?xml version="1.0" encoding="UTF-8"?>
<root>xxx</root>

Adding

If this is the expected behavior in this case, then what is the value of the matching attribute necessary to match the element contentin the second case?

+3
source share
2

? , . , , - . -, ( , ). , <xsl:template match="content">, <content> XML , http://test.com ( ). .

+2

XPath/XSLT.

XPath " ".

Wpath Xpath :

QName , URI null.

(, "someName" ) , XML- " ", someName "someName", "no namespace".

:

, , .

:

<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="http://test.com" exclude-result-prefixes="x">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>

        <xsl:template match="/">
            <root>
                <xsl:apply-templates/>
            </root>
        </xsl:template>

        <xsl:template match="x:content">
            <w>x</w>
        </xsl:template>
</xsl:stylesheet>

XML- :

<root xmlns="http://test.com">
    <content>xxx</content>
</root>

, :

<root>
   <w>x</w>
</root>
+5

All Articles