xsl-list
[Top] [All Lists]

RE: XML Group with XSL

2004-04-21 09:17:40
-----Original Message-----
From: Patel, Viral [mailto:viral(_dot_)patel(_at_)countryfinancial(_dot_)com]

You xsl should look something like:


Hi,

The proposed solution won't yield the desired result. The result from your
code would look something like

<ROOT>
  <node_1 ...>
    <node_1 ...>
    <node_1 ...>
  </node_1>
</ROOT>

The intention was good, but it needs to be modified like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>

<xsl:template match="/">
      <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0"
encoding="ISO-8859-1"?&gt;</xsl:text>

??? Why are you explicitly inserting the XML declaration in this way?
If you use <xsl:output method="XML" /> (which is the default BTW), the XML
declaration will be added anyway, and so, if you subsequently use xsl:text
to insert it again, the resulting XML document will be in error.

So, remove the <xsl:text ...> !! If you really need 'ISO-8859-1' encoding
for the result, just add the following as child of xsl:stylesheet :

<xsl:output method="XML" encoding="ISO-8859-1" />

Apply templates only to the first node_1 node:

  <ROOT>
    <xsl:apply-templates select="ROOT/node_1[1]" />
  </ROOT>


And in the template matching the node_1 nodes, create a copy, then copy the
attributes, and finally copy all children of the current node as well as the
children of the other (following-sibling) node_1 nodes :

<xsl:template match="node_1">
  <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:copy-of select="* | following-sibling::node_1/*" />
  </xsl:copy>
</xsl:template>


Hope this helps!

Cheers,

Andreas



<Prev in Thread] Current Thread [Next in Thread>