XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Sushant PrabhuSubject: xsl does not work if input xml root element has attributes
Author: Sushant Prabhu
Date: 11 Apr 2007 09:35 AM
Hi All,

Currently we are using a xsl piece of code we found on the internet for breaking a huge xml into smaller files.
This code works fine but it works only when the root xml element has no attributes. The code fails to render the output wehn the input xml file has an xml root element with attribute.
To illustrate the code works fine if I have the following input xml
---------------------- THIS WORKS --------------
<header>...
<instances>
<instance>...</instance>
<instance>...</instance>
...
<instance>...</instance>
</instances>
</header>
---------------------- THIS WORKS --------------

---------------------- THIS DOES NOT WORK --------------
<header xmlns="http://www.vignette.com/xmlschemas/importexport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vignette.com/xmlschemas/importexport 7202/packageBody.xsd">...
<instances>
<instance>...</instance>
<instance>...</instance>
...
<instance>...</instance>
</instances>
</header>
---------------------- THIS DOES NOT WORK --------------


The xsl code we are using very similar to one found on this location
--------------------------
http://www.biglist.com/lists/xsl-list/archives/200407/msg00949.html
--------------------------

Do post your suggestions on the same. It does not give any error but just does not generate the output files.


Regards,

Postnext
(Deleted User) Subject: xsl does not work if input xml root element has attributes
Author: (Deleted User)
Date: 11 Apr 2007 10:09 AM
Hi Sushant,
I think the problem is not that the header has attributes, but that it has a xmlns="..." namespace declaration.
In this case, you cannot just specify an XPath expression like "/header", but you need to use the proper namespace prefix (e.g. "/p:header" where "p" is defined by a xmlns:p="..." attribute of the xsl:stylesheet element).

Hope this helps,
Alberto

Postnext
Sushant PrabhuSubject: xsl does not work if input xml root element has attributes
Author: Sushant Prabhu
Date: 11 Apr 2007 10:58 AM
Hi Alberto,

Thanks for your response.

I tried to do something like this & now the xsl stylesheet declaration is something like this

-----------------------------
<xsl:stylesheet version="1.0"
xmlns:p="http://www.vignette.com/xmlschemas/importexport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vignette.com/xmlschemas/importexport 7202/packageBody.xsd"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
xmlns:xalanredirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="xalanredirect redirect"
>

--------------------------------


& in my xsl code i am referring to the xml tags which are part of the namespaces something like this

<xsl:variable name="totalines"><xsl:value-of
select="count(/p:packageBody/importChannel)" /></xsl:variable>

and

<xsl:for-each select="p:packageBody/importChannel">


But still I am not able to run it successfully.

Do let me know if I am missing something here.


Regards




Postnext
(Deleted User) Subject: xsl does not work if input xml root element has attributes
Author: (Deleted User)
Date: 11 Apr 2007 11:37 AM
Hi Sushant,
you need to apply the "p" prefix to all the element names (like in p:importChannel), not only to the root node.

Alberto

Posttop
Sushant PrabhuSubject: xsl does not work if input xml root element has attributes
Author: Sushant Prabhu
Date: 11 Apr 2007 11:45 AM
Thanks Alberto

That worked.


 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.