Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML to XML newbee help

From: dingbat@----------.--- (---- -------)
To: NULL
Date: 7/5/2004 4:31:00 AM
adam44@b... (Adam) wrote in message news:<6e8eb718.0407010129.534c4a7b@p...>...
> Hi, Me very confused. I have some XML that I want to convert to a more
> basic XML. I have put an example of what I have and what I want, 

Try this:

Notes: 
 - I'm ingnoring some whitespace issues that are rarely significant.
You'd need to supply a better spec before going there.

 - I guess the text of the second link in your example was a typo. 

 - This is an impossible problem to solve, as a general case from one
example. I can make it work (quite easily) for that one case, but a
couple of examples don't _define_ a mapping (I had to guess at this,
and it's a 50:50 guess between whether to map <item> or <par
class="MainText"> as the output <para>).

As a reductio ad absurdum, I could simply have wrapped your output
example in a <xsl:template> element (literal text and all !) and
called that a valid solution to the stated question. You see the
problem ?


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    exclude-result-prefixes="xlink"
    >

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>


<xsl:template match="link" >
  <link href="{@xlink:href}" ><xsl:value-of select=".//text()"
/></link>
</xsl:template>

<xsl:template match="par[@class='Normal']" />

<xsl:template 
  match="par[@class='MainText']" >
  <para>
  <xsl:value-of select="translate (parent::item/@numberingtext,
'&#9;', ' ')" />
  <xsl:apply-templates select="* | text()" />
  </para>
</xsl:template>


<xsl:template 
  match="par[@class and not (@class = 'Normal' or @class =
'MainText')]" >
  <xsl:element name="{./@class}" ><xsl:value-of select="text()"
/></xsl:element>
</xsl:template>


<xsl:template match="document/part" >
  <root>
  <xsl:apply-templates select="*" />
  </root>
</xsl:template>

</xsl:stylesheet>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent