Re: [xsl] Tag within tag

Subject: Re: [xsl] Tag within tag
From: Peter Flynn <peter@xxxxxxxxxxx>
Date: 05 Apr 2003 00:18:40 +0100
On Fri, 2003-04-04 at 22:48, David B. Bitton wrote:
> I have the following XML:
> 
> <body>
> 	Subscriber agrees to pay Company the sum of $
> 	<sub name="install" />
> 	, plus tax, if applicable, for the installation (and sale if the System 
> is sold) of the System as follows: $
> 	<sub name="down_pmt" />
> 	upon signing this Agreement; $
> 	<sub name="pre_wire_pmt" />
> 	upon pre-wiring, if necessary; $
> 	<sub name="final_pmt" />
> 	upon substantial completion of installation.
> </body>
> 
> I have the following template for the <body> element:
> 
> <xsl:template match="body">
> 	<fragment font="Helvetica" fontsize="7">
> 		<xsl:value-of select="."/>
> 	</fragment>		
> </xsl:template>
> 
> but I don;t know how to handle a <sub> element within <body> if it 
> occurrs.  What do I need to do?  BTW, XPath 1.0 :)

Don't use value-of for processing the normal content of elements,
and especially not where there are subelements. Value-of simply
extracts the string value, ignoring all element markup, which is
the opposite of what you want. Instead, use <xsl:apply-templates/>
which means "process the content of this element using any
further templates that apply". Create a template to match "sub"
and put in it whatever is relevant.

But you have a more serious problem, I think: all that extraneous
white-space is going to cause problems if you are producing formatted
output, because you'll have a space after every dollar sign, which
in some circumstances may cause line-breaks to occur in unwanted
locations. Fix the XML so it says:

  <body>Subscriber agrees to pay Company the sum of $<sub 
  name="install"/>, plus tax, if applicable, for the 
  installation (and sale if the System is sold) of the 
  System as follows: $<sub name="down_pmt"/> upon signing 
  this Agreement; $<sub name="pre_wire_pmt"/> upon 
  pre-wiring, if necessary; $<sub name="final_pmt"/>
  upon substantial completion of installation.</body>

or similar. 

///Peter



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


Current Thread