[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Saxon8: XML to XML transformation

Subject: RE: Saxon8: XML to XML transformation
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 28 Aug 2006 12:00:47 +0100
saxon8 transform
XMLSpy is probably taking its input from the Microsoft MSXML3 parser, which
notoriously strips whitespace text nodes from the input without you asking
it to. When you do

<xsl:apply-templates select="../superclass/class/child::node()"/>

you are selecting three nodes: two whitespace text nodes, and an element,
and you are processing all of these. The default rule for a text node is to
copy it to the output.

To make your stylesheet work with a standards-compliant XML parser, either
change the above to:

<xsl:apply-templates select="../superclass/class/child::*"/>

so you only process child element nodes, or (preferably) write

<xsl:strip-space elements="*"/>

at the top level of the stylesheet, to indicate that all whitespace text
nodes should be removed before further processing.

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: Marco Pehla [mailto:marco.pehla@xxxxxxxxxxxxxx] 
> Sent: 28 August 2006 11:37
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Saxon8: XML to XML transformation
> 
> Hello everybody,
> 
> I've got a little problem and don't know how to solve it. I 
> use Saxon8 inside a JavaBean and want to transform some data 
> from an XML file to another XML file. If I use XMLSpy and 
> apply the XSLT transformation to the XML file I get the 
> desired output, but not with Saxon8.
> 
> What am I supposed to do to get the same output like with 
> XMLSpy? Why does Saxon behave like that?
> 
> 
> Thank you in advance,
> with kind regards,
> Marco
> 
> 
> XML input:
> ---------------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <molecule>
>   <object>
>     <variable name="marco"/>
>   </object>
>   <superclass isaType=":">
>     <class>
>       <constant name="employee"/>
>     </class>
>   </superclass>
> </molecule>
> 
> 
> XMLSpy output:
> -----------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <ObjectClassificationAtom class="employee">
>         <ObjectVariable name="marco" class="employee"/> 
> </ObjectClassificationAtom>
> 
> 
> Saxon8 output:
> ----------------------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <ObjectClassificationAtom class="
>       employee
>     ">
>   <ObjectVariable name="
>     marco
>   " class="
>       employee
>     "/>
> 
> </ObjectClassificationAtom>
> 
> 
> my simple XSLT transformation:
> ----------------------------------------------
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:fn="http://www.w3.org/2006/xpath-functions"
> xmlns:saxon="http://icl.com/saxon">
>   <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
> 
>   <xsl:template match="/" >
>     <xsl:apply-templates/>
>   </xsl:template>
> 
>   <xsl:template match="molecule">
>     <xsl:if test="superclass/@isaType = ':'">
>       <xsl:element name="ObjectClassificationAtom">
>         <xsl:attribute name="class">
>           <xsl:apply-templates 
> select="superclass/class/child::node()"/>
>         </xsl:attribute>
>         <xsl:apply-templates/>
>       </xsl:element>
>     </xsl:if>
>   </xsl:template>
> 
>   <xsl:template match="object">
>     <xsl:element name="ObjectVariable">
>       <xsl:attribute 
> name="name"><xsl:apply-templates/></xsl:attribute>
>       <xsl:if test="../superclass">
>         <xsl:attribute name="class">
>           <xsl:apply-templates 
> select="../superclass/class/child::node()"/>
>         </xsl:attribute>
>       </xsl:if>
>     </xsl:element>
>   </xsl:template>
> 
>   <xsl:template match="constant | variable | class">
>     <xsl:value-of select="@name"/>
>   </xsl:template>
>   <!-- ignore all the rest -->
>   <xsl:template match="*"/>
> </xsl:stylesheet>
> 
> --
> http://www.informatik.tu-cottbus.de/~mpehla/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.