1

Currently I'm defining a variable in my XSLT 1.x file like this:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ns1="http://ns.hr-xml.org" >
...
    <xsl:variable name="my_var" select="ns1:RootNode/ns1:Node[3]/ns1:Title" />

Is there a way so that I can somehow define ns1: namespace to be always used so that I could possibly write my variable like this:

<xsl:variable name="my_var" select="RootNode/Node[3]/Title" />
8
  • 2
    If you were able to upgrade to XSLT 2.0, you would be able to use xpath-default-namespace to do this. Commented Jul 1, 2016 at 11:21
  • Thanks @TimC I did found it out but unfortunately I don't have this opportunity to use XSLT 2.0 Commented Jul 1, 2016 at 13:08
  • 3
    Then I am not sure you can do much. You do see people doing something like *[local-name() = 'RootNode'] but this would match all namespaces, not just the required one, and isn't really a good solution anyway. Commented Jul 1, 2016 at 13:15
  • 1
    @HrvojeGolcic Why is this a problem? Commented Jul 1, 2016 at 13:16
  • 1
    This is indeed not supported in XSLT 1.x, see the answer to this post: stackoverflow.com/questions/14274166/…. Another hacky workaround would be to prepend a transformation to remove all namespaces, but I don't even think that I should suggest this. Commented Jul 1, 2016 at 15:15

0

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.