12

I have this simple xml document:

<?xml version='1.0' encoding='UTF-8'?>
<registry xmlns="http://www.iana.org/assignments" id="character-sets">
     <registry id="character-sets-1">
       <record>
         <name>ANSI_X3.4-1968</name>
      </record>
     </registry>
</registry>

When I use this xsl I can extract the name:

<?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.iana.org/assignments" version="1.0">
  <xsl:template match="/my:registry">
      <xsl:copy-of select="//my:record/my:name"/>
  </xsl:template>
</xsl:stylesheet>

However, If I omit the namespace in the xsl xpath-selectors, I get no output:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.iana.org/assignments" xpath-default-namespace="http://www.iana.org/assignments" version="1.0">
  <xsl:template match="/registry">
       <xsl:copy-of select="//record/name"/>
  </xsl:template>
</xsl:stylesheet>

I thought xpath-default-namespace is meant to do the trick. What am I missing?

In case library versions are important I have

libexpat1 (>= 1.95.8)

libxerces-c3.1

libxml2 (>= 2.7.4)

libxslt1.1 (>= 1.1.25)

1 Answer 1

15

Unfortunately xpath-default-namespace is an XSLT 2.0 feature. You'll need to repeat the namespace or alias it in your xpath in xslt 1.0

Reference : Jenni Tennison and IBM

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

2 Comments

Yes, now I see that libxslt1.1 doesn't support xpath-default-namespace Thank you!
How can anyone define xpath-default-namespace in xslt version 1.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.