RE: [xsl] create new elements as output

Subject: RE: [xsl] create new elements as output
From: sara.mitchell@xxxxxxxxx
Date: Tue, 27 Mar 2001 14:11:05 -0500
Bruce, 

There is at least one error that may not be obvious: 

>    <xsl:template match="FareRules">
>    	<xsl:element name="Text"/>

This line above creates an empty element named 'Text' because
of the / at the end (you are both starting and ending an element). 
This element has no attributes and no content, so that may be why
it's not being created. 

>         <xsl:apply-templates select="PenRules"/>         
>         <xsl:apply-templates select="MinStay"/>
>         <xsl:apply-templates select="MaxStay"/>      
>    </xsl:template>

Change this to: 

    <xsl:template match="FareRules">
    	<xsl:element name="Text">
         <xsl:apply-templates select="PenRules"/>         
         <xsl:apply-templates select="MinStay"/>
         <xsl:apply-templates select="MaxStay"/>
      </xsl:element>
    </xsl:template>

to allow <Text> to contain the output of your other templates.

Sara

> -----Original Message-----
> From: Bruce Rosborough [mailto:BRosborough@xxxxxxx]
> Sent: Tuesday, March 27, 2001 10:38 AM
> To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: [xsl] create new elements as output
> 
> 
> Hi.  I appreciate any help that anyone would like to offer.  Thanks.
> Problem: Using XSL in trying to transform XML file into 
> another XML file
> with differing element names and adding a group element.  Use 
> of "name" for
> creating elements is ignored, and don't understand why.
> 
> XML input (text lines of various types):
> 
> <?xml version='1.0' ?>
> <?xml:stylesheet type="text/xsl" href="farerules.xsl"?>
> <FareRules>
>   <PenRules>this text is penalty rules text</PenRules>   
>   <MinStay>this text is minimum stay text</MinStay>
>   <PenRules>this text is penalty rules2 text</PenRules>
>   <MaxStay>this text is maximum stay text</MaxStay>
> </FareRules>
> 
> desired XML output: (text lines categorized, using new 
> element names and
> adding new element for group)
> 
> <Text>
>   <PenaltyRules>this text is penalty rules text</PenaltyRules>
>   <PenaltyRules>this text is penalty rules2 text</PenaltyRules>
>   <MinimumStay>this text is minimum stay text</MinimumStay>
>   <MaximumStay>this text is maximum stay text</MaximumStay> 
> </Text>
> 
> 
> XSL file (used unsuccessfully to try to transform this, aka 
> 'faresrules.xsl'
> )
> 
> <?xml version="1.0"?>
> <!--<xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>-->
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>   
>    <xsl:template match="/">
>      <xsl:apply-templates/>
>    </xsl:template>    
>    <xsl:template match="FareRules">
>    	<xsl:element name="Text"/>
>         <xsl:apply-templates select="PenRules"/>         
>         <xsl:apply-templates select="MinStay"/>
>         <xsl:apply-templates select="MaxStay"/>      
>    </xsl:template>
>    <xsl:template match="PenRules">      
>      <xsl:element name="PenaltyRules">      
>        <xsl:value-of select="."/>
>      </xsl:element>	           
>    </xsl:template>   
>    <xsl:template match="MinStay">
>      <xsl:element name="MinimumStay">      
>        <xsl:value-of select="."/>
>      </xsl:element>	           
>    </xsl:template> 
>    <xsl:template match="MaxStay">
>         <xsl:element name="MaximumStay">      
>           <xsl:value-of select="."/>
>         </xsl:element>	           
>    </xsl:template>     
> </xsl:stylesheet>
> 
> 
> Thanks again.
> 
> Bruce
> BRosborough@xxxxxxx
> www.xol.com 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread