4

I have a xml which contains empty xmlns:tag0='' is there a way I can ignore namespaces alltogether or add some default value to it? Because it is stopping my xml to open with xsl transformations. It says Reference to undeclared namespace prefix: 'tag0'.

Or is there a way I can replace xmlns:tag0='' with xmlns:tag0='http://www.w3.org/TR/html4/ at the beginning?

Some part of xml which creates problem (xml is around 2MB)

<nodemetadata><imx:IMX versiondomainservice='2.4.1' versioncommon='2.2.0' serializationSpecVersion='4.0' xsi:schemaLocation='http://com.abc.imx IMX.xsd http://com.abc.aspd.metadata.domainservice/2 com.abc.aspd.metadata.domainservice.xsd http://com.abc.aspd.metadata.common/2 com.abc.aspd.metadata.common.xsd' crcEnabled='0' xmlns:imx='http://com.abc.imx' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><tag0:GatewayNodeConfig adminconsolePort='10073' nodeName='node01_rox.abc.com' imx:id='U:qywCXNr7EeG7SZfVCvSloA' domainName='Domain_rox.abc.com' dbConnectivity='ID_1' adminconsoleShutdownPort='10074' xmlns:tag0='http://com.abc.aspd.metadata.domainservice/2'><tag1:address port='10071' xsi:type='common:NodeAddress' host='rox.abc.com' httpPort='8080' imx:id='ID_2' xmlns:tag1=''></tag1:address><portals><tag1:NodeRef xsi:type='common:NodeRef' address='ID_2' nodeName='node01_rox.abc.com' imx:id='ID_3' xmlns:tag1=''></tag1:NodeRef></portals></tag0:GatewayNodeConfig><tag0:DBConnectivity imx:id='ID_1' dbConnectString='jdbc:abc:oracle:%2F%2FforKnight:1521%3BServiceName%3Dorcl%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue' dbType='ORACLE' dbEncryptedPassword='I7e20Erjax0wi7fY3qOaIxIBloTOBwLymgjvVVbkVcE%3D' dbUsername='lap1' xmlns:tag0='http://com.abc.aspd.metadata.domainservice/2'></tag0:DBConnectivity></imx:IMX></nodemetadata>

UPDATE My XSL code

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
    xmlns:tag0="http://www.w3.org/TR/html4/"
    xmlns:tag1="http://www.w3.org/TR/html4/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:imx="http://com.abc.imx" 
    xmlns:domainservice="http://com.abc.aspd.metadata.domainservice/2"
    exclude-result-prefixes="tag0 tag1">

<xsl:include href="system_win.xsl"/>
<xsl:include href="system_nix.xsl"/>

<xsl:template match="/">
<html>
<head><link rel="stylesheet" type="text/css" href="http://www.abc.com/NR/inter2004/css/styles.css"/>
<style type="text/css">
.horz{overflow-x: auto; overflow-y: hidden;width: 98%;}
</style>
</head>
<body>
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
    <xsl:for-each select="client/product">

        <h3><span style="color:#328aa4"><a name="_nodemetadata" href="#_top">Node MetaData</a></span></h3>
        <h3>Gateway Node Configuration</h3>
        <br/>
        <dd>
        <div class="horz">
            <table border="1">
                <tbody>
                <tr>
                    <th>Domain Name</th>
                    <th>Node Name</th>
                    <th>Adminconsole Port</th>
                    <th>Adminconsole Shutdown Port</th>
                    <th>DB Connectivity</th>
                </tr>
                <xsl:for-each select="nodemetadata/imx:IMX/tag0:GatewayNodeConfig">
                    <tr>
                        <td valign="top" ><xsl:value-of select="@domainName"/></td>
                        <td valign="top" ><xsl:value-of select="@nodeName"/></td>
                        <td valign="top" ><xsl:value-of select="@adminconsolePort"/></td>
                        <td valign="top" ><xsl:value-of select="@adminconsoleShutdownPort"/></td>
                        <td valign="top" ><xsl:value-of select="@dbConnectivity"/></td>
                    </tr>
                </xsl:for-each>
                </tbody>
            </table>
        </div>
        </dd>
        <br/>
    </xsl:for-each>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

It gives me XML Parsing Error: must not undeclare prefix on tag0

AabinGunz
  • 12,109
  • 54
  • 146
  • 218
  • @Tomalak: Can't i use some XSLT transformation using ` – AabinGunz Aug 07 '12 at 13:40
  • @AbhishekSimon If your input is fixed, then the XSLT in my link above should start to work - or doesn't it? – Tomalak Aug 07 '12 at 13:47
  • @Tomalak: Your link works good! but the problem comes when both xsl and xml are actual files, may be the site has some own settings which is letting it render the xml with the stylesheet, but if I copy the contents of each xsl(t) and xml frames content into a file with `` added for stylesheet in xml file, it gives a error in browser saying error processing resource. I am using IE8 – AabinGunz Aug 07 '12 at 13:55
  • How to make XSLT work in IE8 is material for a different question (or a web search). In my world, XSLT runs on the server, not on the client, so I'm afraid can't help you with that. – Tomalak Aug 07 '12 at 14:13
  • @Tomalak: Thanks for your patience with me :) Also the xsl works good with IE8, but it's just not working with the current xml right now because of this empty `xmlns:tag1=''` Just 1 last question, any other way I can transform the xml so `xmlns:tag1=''` could be eliminated? – AabinGunz Aug 07 '12 at 14:19
  • Since I have no idea how the `xmlns:tag1=''` gets *into* your XML - no. That's the place where you have to look. After that declaration is in your XML there is no way to fix it (except search-and-replace on the XML string). – Tomalak Aug 07 '12 at 14:27

1 Answers1

0

After you fixed your input XML, the following XSLT 1.0 stylesheet is working as required:

also see http://www.xmlplayground.com/XyNCuA

<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:imx="http://com.abc.imx" 
  xmlns:domainservice="http://com.abc.aspd.metadata.domainservice/2"
  exclude-result-prefixes="imx domainservice"
>
  <xsl:output method="html" />

  <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

  <xsl:template match="/">
    <html>
    <head>
      <link rel="stylesheet" type="text/css" href="http://www.abc.com/NR/inter2004/css/styles.css"/>
      <style type="text/css">
        .horz{overflow-x: auto; overflow-y: hidden;width: 98%;}
      </style>
    </head>
    <body>
      <p>(see output source)</p>
      <xsl:apply-templates select="client/product/nodemetadata" />
    </body>
    </html>
  </xsl:template>

  <xsl:template match="nodemetadata">
    <h3><span style="color:#328aa4"><a name="_nodemetadata" href="#_top">Node MetaData</a></span></h3>
    <xsl:apply-templates select=".//domainservice:GatewayNodeConfig" />
  </xsl:template>

  <xsl:template match="domainservice:GatewayNodeConfig">
    <h3>Gateway Node Configuration</h3>
    <dd>
       <div class="horz">
         <table border="1">
           <thead>
             <tr>
               <th>Domain Name</th>
               <th>Node Name</th>
               <th>Adminconsole Port</th>
               <th>Adminconsole Shutdown Port</th>
               <th>DB Connectivity</th>
             </tr>
           </thead>
           <tbody>
             <tr>
               <td valign="top" ><xsl:value-of select="@domainName"/></td>
               <td valign="top" ><xsl:value-of select="@nodeName"/></td>
               <td valign="top" ><xsl:value-of select="@adminconsolePort"/></td>
               <td valign="top" ><xsl:value-of select="@adminconsoleShutdownPort"/></td>
               <td valign="top" ><xsl:value-of select="@dbConnectivity"/></td>
             </tr>
           </tbody>
         </table>
       </div>
     </dd>
     <br/>
   </xsl:template>
</xsl:stylesheet>

output:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="http://www.abc.com/NR/inter2004/css/styles.css">
<style type="text/css">
        .horz{overflow-x: auto; overflow-y: hidden;width: 98%;}
      </style>
</head>
<body>
<p>(see output source)</p>
<h3><span style="color:#328aa4"><a name="_nodemetadata" href="#_top">Node MetaData</a></span></h3>
<h3>Gateway Node Configuration</h3>
<dd><div class="horz"><table border="1">
<thead><tr>
<th>Domain Name</th>
<th>Node Name</th>
<th>Adminconsole Port</th>
<th>Adminconsole Shutdown Port</th>
<th>DB Connectivity</th>
</tr></thead>
<tbody><tr>
<td valign="top">Domain_rox.abc.com</td>
<td valign="top">node01_rox.abc.com</td>
<td valign="top">10073</td>
<td valign="top">10074</td>
<td valign="top">ID_1</td>
</tr></tbody>
</table></div></dd>
<br>
</body>
</html>
Tomalak
  • 332,285
  • 67
  • 532
  • 628