1
votes

Is there a way in xsl 1.0 to mention the xpath expression as below, to get the value of node "a"

/Root/a - doesnt work

instead of

/Root/*[local-name() = 'a'] - this will work

This is my xml file

<Root xmlns:ns="http://abc">
  <ns:a>value</ns:a>
</Root>

The reason am asking, in my xslt, in many lines, we specified the xpath expression as /Root/a (or other nodes), because the xml file did not have any namespaces before. However the xml file has namespaces now, we have to change everywhere, with *[local - name()]. Instead of that, is there a way to change my xsl, in one place, so that the earlier xpath expressions also work, even with namespace included xml?

1
If your renamed /Root/a to /Root/b, how can you change your xsl in one place so that the earlier xpath expressions also work?choroba

1 Answers

0
votes

If you are using XSLT 2.0, you can declare xpath-default-namespace. In XSLT 1.0 is better to declare namespace prefix and use it in XPath expressions, than use local-name() function e.g.:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://abc"/>

In XPath:

/Root/ns:a