0

I have a xml file which I have to parse with xslt, but the problem is that in the root node I have a link, which doesn't let me parse the xml file. If I delete that link from the xml file, I can parse the file. xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<ROOT xmlns="http://link.org/3.2.1">
  <TOP-LEVEL-PACKAGES>
    <AR-PACKAGE>
      <SHORT-NAME>ActiveEcu</SHORT-NAME>
</AR-PACKAGE>
</TOP-LEVEL-PACKAGES>
</ROOT>

But I should not modify the xml file, so I need a solution to parse it without delete that link. Any solution?

Ariana Bitu
  • 39
  • 1
  • 2

1 Answers1

0

in the stylesheet node add something like this xmlns:ns1="link.org/3.2.1"; then when referring the root node use the following syntax: ns1:ROOT

Basically your ROOT node is associated to default namespace represented the URL. In the xslt template you have to mention the namspace to URL to tell the XSLT parser that ROOT node belongs to that specific namespace

In fact all child nodes of your given xml belongs the default namespace represented by the URL

For example

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                             exclude-result-prefixes="xsl"
                xmlns:ns1="http://link.org/3.2.1">
  <xsl:template match="/">
    <xsl:value-of select="ns1:ROOT"/>
  </xsl:template>
</xsl:stylesheet>
Saurav
  • 592
  • 4
  • 21
  • Thanks for your answer Saurav, but I already tried this and it doesn't seems to work.. :( – Ariana Bitu Jan 19 '15 at 12:24
  • can you post the xslt – Saurav Jan 19 '15 at 12:31
  • 1
    @ArianaBitu: please do not attempt to post code in the comment box. As you can see, it's pretty unreadable. Also, comments may be deleted any time and should not contain crucial information. Instead, [edit](http://stackoverflow.com/posts/28023399/edit) your question and insert it in there. – Jongware Jan 19 '15 at 13:12
  • Please use the following ns:ROOT/ns:TOP-LEVEL-PACKAGES/ns:AR-PACKAGE/ns:SHORT-NAME I had mentioned in my answer that your all child nodes also belong to that URL – Saurav Jan 19 '15 at 13:13
  • Mention not. Then perhaps you can accept the answer – Saurav Jan 19 '15 at 15:13