2

I am trying to process XML/XSL using XSLT. The XML and parts of XSL contains of prefixed namespaces. My understanding is that it is enough to have the namespace declaration(s) in XSL file.

The XML file must have namespace prefix, I do not have an option to just remove them as a solution since it changes the XML data structure.

I have tried with declaring the xbrli namespace in the XML file, but the error is the same as If I would exclude it in that file.

Problem: I do not find what is causing the error, thus cannot isolate the root cause.

Resources I used for troubleshooting:

W3C - Namespaces in XML 1.0

W3C - XSL 2.0 Specification

Saxonica - Saxon documentation


Error after XSLT has processed:

Saxon-HE 10.5J from Saxonica
Java version 11.0.10
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
using class net.sf.saxon.tree.tiny.TinyBuilder
Error on line 3 column 13 of annual_report_example_3_xbrl_mini.xml:
  SXXP0003   Error reported by XML parser: The prefix "xbrli" for element "xbrli:xbrl" is
  not bound.: The prefix "xbrli" for element "xbrli:xbrl" is not bound.
org.xml.sax.SAXParseException; systemId: file:/Xxx; lineNumber: 3; columnNumber: 13; The prefix "xbrli" for element "xbrli:xbrl" is not bound.

XML file:

<?xml version="1.0" encoding="UTF-8" ?>

<xbrli:xbrl>
  <se-cd-base:Country>Sweden</se-cd-base:Country>
</xbrli:xbrl>

XSL file:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xbrli="http://www.example.org/area-2"
  xmlns:se-cd-base="http://www.example.org/area-3"
  xmlns:ix="http://www.example.org/area-4"
  xmlns="http://www.w3.org/1999/xhtml"
  >

  <xsl:template match="/xbrli:xbrl">

    <html>

      <head>
        <title>MyTitle</title>
      </head>

      <body>
        <ix:nonNumeric name="se-cd-base:Country">
          <xsl:value-of select="se-cd-base:Country"/>
        </ix:nonNumeric>
      </body>

    </html>

  </xsl:template>

</xsl:stylesheet>

Expected output

<html>

      <head>
        <title>MyTitle</title>
      </head>

      <body>
        <ix:nonNumeric name="se-cd-base:Country">
          Sweden
        </ix:nonNumeric>
      </body>

  </html>

2 Answers 2

3

The namespaces you refer to in your transformation are not declared in your input file.

If you modify your input file to declare the namespaces, like this:

<?xml version="1.0" encoding="UTF-8" ?>
<xbrli:xbrl xmlns:xbrli="http://www.example.org/area-2" xmlns:se-cd-base="http://www.example.org/area-3">
  <se-cd-base:Country>Sweden</se-cd-base:Country>
</xbrli:xbrl>

Your transformation works.

Edit: Your xsl:value-of is not working because your template is selecting the root element but the value is in a child element. Simply replace it with this:

<xsl:value-of select="xbrli:xbrl/se-cd-base:Country"/>

See it working here: https://xsltfiddle.liberty-development.net/gVAkJ3L/1

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

3 Comments

Your suggestion removed all errors. Only missing to get the expected result is to make visible the "xsl:value-of" that should return "Sweden" in this case.
@Toolbox See my updated answer for the xsl:value-of.
I adjusted the match="/xbrli:xbrl", then the XML data value shows up in end result. I have approved you answer.
2

The section https://www.w3.org/TR/xml-names/#nsc-NSDeclared in your cited spec expressly requires about prefixes used in element or attribute names

The namespace prefix, unless it is xml or xmlns, MUST have been declared in a namespace declaration attribute in either the start-tag of the element where the prefix is used or in an ancestor element

So basically your input sample using prefixes in names like xbrli:xbrl without any namespace declaration is not namespace well-formed XML and can't be used with any XSLT processor as XPath and XSLT work on XML with namespaces in the sense of having a namespace well-formed XML input.

1 Comment

- Thanks, it means I receive a fault XML with missing namespace, but I am allowed to add the namespace declaration and then it works fine with XSLT.

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.