none
Wildcards and namespaces in XPATH/XSLT??

    Question

  • Hi there,

     

    When I use a wildcard with a namespace (like *:XMLElementName) in "Altova XML spy" everything works fine. I thought it's also allowed by the W3C specification.

    When I use this statement

     

    <xsl:for-each select="/root/workflowgegevens/Base_Workflow.WorkflowExport/ExportXml/*:AanstellingDto">

                <xsl:element name="AanstellingsGegevens">

                            <xsl:call-template name="Aanstelling"/>

                            <xsl:call-template name="AlgemeneGegevens"/>

                            <xsl:call-template name="Contract"/>

                </xsl:element>

    </xsl:for-each>

     

    in my XSLT XML NotePad, Visual Xpath, my own Script task in SSIS or other tools I generates this error :

     

    /root/workflowgegevens/Base_Workflow.WorkflowExport/ExportXml/*:AanstellingDto' is an invalid XPath expression. An error occurred at file:///C:/Projecten/Interfaces/SSIS/XSLT/ExportAanstelling.xslt(18,7)."

     

    Is there anybody who knows what’s wrong? And if it is allowed to use wildcards for namespaces in XSLT/ xpath expressions?

     

    Thanks in advance,

    With regards,

     

    Patrick de Jong

     

    Friday, April 18, 2008 9:23 AM

Answers

  • The XPath 1.0 recommendation doesn't allow * as a prefix but you can use an expression such as *[local-name()='AanstellingDto']
    Friday, April 18, 2008 11:21 AM
  • Altova already supports XPath and XSLT 2.0 while the .NET framework's XslCompiledTransform only supports XPath and XSLT 1.0. And with XPath 1.0 '*' is allowed to select all elements and pf:* is allowed to select all elements in the namespace bound to the prefix 'pf' but *:foo to select 'foo' elements in all namespaces is not allowed in XPath 1.0, see http://www.w3.org/TR/xpath#node-tests.

    As already suggested you can use *[local-name() = 'foo'] to work around that.

    Friday, April 18, 2008 11:31 AM

All replies

  • The XPath 1.0 recommendation doesn't allow * as a prefix but you can use an expression such as *[local-name()='AanstellingDto']
    Friday, April 18, 2008 11:21 AM
  • Altova already supports XPath and XSLT 2.0 while the .NET framework's XslCompiledTransform only supports XPath and XSLT 1.0. And with XPath 1.0 '*' is allowed to select all elements and pf:* is allowed to select all elements in the namespace bound to the prefix 'pf' but *:foo to select 'foo' elements in all namespaces is not allowed in XPath 1.0, see http://www.w3.org/TR/xpath#node-tests.

    As already suggested you can use *[local-name() = 'foo'] to work around that.

    Friday, April 18, 2008 11:31 AM
  • If you want to use XSLT/XPath 2.0 with your .NET applications then you can use Saxon's .NET version from http://saxon.sourceforge.net/ or AltovaXML from http://www.altova.com/altovaxml.html

    Friday, April 18, 2008 11:55 AM
  • Does anybody have any pros/cons for each of those packages?

     

    Wednesday, December 03, 2008 8:51 PM
  • AltovaXML supports schema aware XSLT 2.0 and XQuery 1.0 while Saxon comes in two versions, the open source basic version that is not schema aware and the schema aware commercial SA version.

    As for using the products with .NET, Saxon is mainly developed in Java and then cross compiled to .NET. AltovaXML is a COM solution that allows usage from .NET via COM interop.

    Thursday, December 04, 2008 12:51 PM