Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2012, 08:04 AM
Registered User
 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml indent looses namespace

Hello everybody, I know little about XSLT, but i need a very simple thing. Basically i need to format (indent) an xml file. This transformation already does everything i need:

Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:patchv2="http://patchv2.dnbgp.dnb.com/schema/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <xsl:output method="xml"/>
   <xsl:param name="indent-increment" select="'   '" />

   <xsl:template match="*">
      <xsl:param name="indent" select="'&#xA;'"/>
      <xsl:value-of select="$indent"/>
      <xsl:copy>
        <xsl:copy-of select="@*" />
        <xsl:apply-templates>
          <xsl:with-param name="indent" select="concat($indent, $indent-increment)"/>
        </xsl:apply-templates>
        <xsl:if test="*">
          <xsl:value-of select="$indent"/>
        </xsl:if>
      </xsl:copy>
   </xsl:template>
   <xsl:template match="comment()|processing-instruction()">
      <xsl:copy />
   </xsl:template>
   <!-- WARNING: this is dangerous. Handle with care -->
   <xsl:template match="text()[normalize-space(.)='']"/>
</xsl:stylesheet>
The problem though is that this works fine for simple xml (no workspace....), but my xml file:
Code:
<patchv2:patchList xmlns:patchv2="http://patchv2.dnbgp.dnb.com/schema/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ci-dnbi.us.dnb.com/standards/schema/patchv2-2.0.2.xsd" xsi:schemaLocation="http://patchv2.dnbgp.dnb.com/schema/2.0.0 http://ci-dnbi.us.dnb.com/standards/schema/patchv2-2.0.2.xsd">
	<patchv2:patchEntry>
		<patchv2:patchVersion>RT60.2NA2A</patchv2:patchVersion>
        </patchv2:patchEntry>
        ...
</patchv2:patchList>
gets tranformed (indented correctly) to:
Code:
<patchList xmlns:patchv2="http://patchv2.dnbgp.dnb.com/schema/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ci-dnbi.us.dnb.com/standards/schema/patchv2-2.0.2.xsd" xsi:schemaLocation="http://patchv2.dnbgp.dnb.com/schema/2.0.0 http://ci-dnbi.us.dnb.com/standards/schema/patchv2-2.0.2.xsd">
   <patchEntry>
      <patchVersion>RT60.2NA2A</patchVersion>
   </patchEntry>
        ...
</patchList>
Can someone helps me to change the transformation so it will keep the patchv2: bit? Thank you.....
 
Old July 9th, 2012, 08:39 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Does <xsl:output method="xml" indent="yes"/> not do the indenting for you (perhaps alongside a <xsl:strip-space elements="*"/> instruction). Trying to manually output significant whitespace like this is fraught with issues.

As for the error you are seeing - xsl:copy should copy namespaces, so what you are reporting doesn't tally with what I see when I try it.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old July 9th, 2012, 09:31 AM
Registered User
 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you samjudson,

you are right, when applying the transformation by itself (let's say in netbeans) the nodes names persists and are correct. So i guess the problem is because i am applying the stylesheet in my java code....

Going to check that now... thanks again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing namespace url from source xml in target xml Hexxor XSLT 0 January 25th, 2012 03:44 AM
error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'Syste shailesh_kumar C# 2008 aka C# 3.0 8 August 20th, 2009 03:11 AM
Need to convert an existing namespace and add new namespace to the SOAP xml Prabeen XSLT 10 April 28th, 2009 10:18 AM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.