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 November 14th, 2006, 11:13 AM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to whiteadi
Default tree xml to flat xml

Hi,

I have an "normal" xml,

a structure like

<x ...>
    <y ...>
      <z ...>
      </z>
     </y>
</x>

and I want to have a "flat" xml

<x .../>
<y .../>
<z .../>
so each node with its name and all attributes with original valus just not tree but with nodes not imbricated.(I have the unique ids already to know parent-child).

I try something like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:template match="x | y | z">
   <xsl:text>< </xsl:text>
   <xsl:value-of select="name(.)" />
    <xsl:for-each select="@*">
    <xsl:value-of select="name()" />=<xsl:value-of select="." />
    </xsl:for-each>
    <xsl:text disable-output-escaping="yes"> /></xsl:text>
      <xsl:apply-templates select="@*|node()"/>
  </xsl:template>
</xsl:stylesheet>

but have the error on <xsl:text>< </xsl:text>.

Best regards,
white

 
Old November 14th, 2006, 01:24 PM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to whiteadi
Default

Resolved,an root must be given.(James Durning did it)

Like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<ENHANCED>
<xsl:apply-templates />
</ENHANCED>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
</xsl:copy>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

 
Old November 14th, 2006, 02:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your XML is not well-formed, a < character must always be escaped as &lt;.

But your stylesheet is a bad example of tag abuse. There's no need and no good reason to use disable-output-escaping here, or to write start and end tags rather than writing nodes. In fact, I think your transformation is nothing more than

<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  </xsl:copy>
  <xsl:apply-templates/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in making a FLAT xml to a structured xml shlomi XSLT 0 July 19th, 2007 07:58 AM
Flat XML to tree Dia XSLT 1 November 16th, 2006 05:11 AM
Flat XML structure to a tree by XSLT Borg0011 XSLT 2 July 9th, 2006 08:58 AM
flat XML to hierarchical XML eduijs XSLT 1 April 28th, 2006 05:43 AM
translating a flat xml to a hierarchical xml stevea XSLT 4 June 13th, 2005 05:55 PM





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