Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - XML to XML newbee help >Thread Next - Re: XML to XML newbee help Re: XML to XML newbee helpTo: 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,
'	', ' ')" />
<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>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
