comp.text.xml
[Top] [All Lists]

Re: simplifying transform

Subject: Re: simplifying transform
From: David Carlisle
Date: Tue, 22 Jul 2008 23:41:51 +0100
Newsgroups: comp.text.xml


David Schwartz wrote:
Thanks for your help Martin. I'd like to explore this in steps if
possible. So when I execute the following transform, I don't get any
attributes. Any ideas as to why? Shouldn't I get all the nodes in
their original state?

   <xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     version="1.0"
     xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
     extension-element-prefixes="redirect">

     <xsl:template match="@* | node()">
        <redirect:write file="transformed.xml">
               <xsl:copy>
                 <xsl:apply-templates select="@* | node()"/>
               </xsl:copy>
        </redirect:write>
     </xsl:template>

TIA!
David

That template is generating a file (with the same noame over and over again) for every element, in the case of attributes it tries to copy the attribute on its own to a new file but without an element to hold it, that can't work.

If you just want to redirect the result of an identity transform then you don't want a new file on every element, just the root:

 <xsl:template match="@* | node()">

               <xsl:copy>
                 <xsl:apply-templates select="@* | node()"/>
               </xsl:copy>

     </xsl:template>

 <xsl:template match="/">
        <redirect:write file="transformed.xml">
        
                 <xsl:apply-templates/>
        
        </redirect:write>
     </xsl:template>

David

--
                                dpcarlisle.blogspot.com">http://dpcarlisle.blogspot.com

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