1

In an XSLT stylesheet, I have set xpath-default-namespace to match the input document that the stylesheet processes. The output document is in the no namespace.

For example, the xsl:stylesheet element has xpath-default-namespace specified:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xpath-default-namespace="http://my.example.com/"
>

Within the transform, I am building elements with no namespace, and I need to match on these elements as well. For now, I use constructs such as:

<xsl:variable name="vCustomElement" as="element()">
   <some_element>
       <!-- element content -->
   </some_element>
</xsl:variable>

<xsl:apply-templates select="$vCustomElement" mode="something" />

.
.

<xsl:template match="*:some_element" mode="something">
    ...
    <xsl:sequence select="." />
    ...
</xsl:template>

This works, but I am curious, is there a way for me to specify no namespace as a prefix in an xpath expression? The above only works, as its matching all namesapces including the no namespace

2 Answers 2

2

In XSLT/XPath 3.0 you can write match="Q{}local" to match a no-namespace element, regardless of the current setting of xpath-default-namespace.

There's no way to do this in 2.0, other than resetting xpath-default-namespace, which you can do on any element with local scope.

Sign up to request clarification or add additional context in comments.

Comments

0

The following works, although, I am still curious if there is someway to specify the no namesapce as a prefix in the match expression

<xsl:template match="some_element" mode="something" xpath-default-expression="">
    ...
    <xsl:sequence select="." />
    ...
</xsl:template>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.