Re: ResultTreeFrag to String

Subject: Re: ResultTreeFrag to String
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 04 Sep 2000 21:51:57 +0100

>If the node has a text child, I will get the sub-tree (String
>representation) of the node, and pass it to a Java extenstion. 

I may well be wrong, but I think that by 'string representation' you mean a
string that looks the same as the original serialised XML?  To do this, you
need a template that will take an XML tree and produce the serialised
version of the tree.  There's no straight-forward way to do this in XSLT -
no automated way of producing a serialised representation of the tree.  But
you can do it by hand using:

<xsl:template match="*" mode="serialise">
  <xsl:value-of select="concat('&lt;', name())" />
  <xsl:for-each select="@*">
    <xsl:value-of select="concat(' ', name(), '=&quot;', ., '&quot;')" />
  <xsl:apply-templates />
  <xsl:value-of select="concat('&lt;/', name(), '&gt;')" />

or something similar (might be wise to escape quotes within the attribute
values, for example).

A final note on terminology.  Usually when we're talking about XSLT, the
'string value' of an element is the value of its content, and its
descendent elements' content, so the 'string value' of the Lease element in:

  <Lessee>ABC Industries</Lessee> 
  agrees to lease the property at 
  <Address>123 Main St., Chicago, IL</Address> 
  <Lessor>XYZ Properties</Lessor> 
  for a term of not less than 
  <LeaseTerm TimeUnit="Months">18</LeaseTerm> 
  at a cost of 
  <Price Currency="USD" TimeUnit="Months">1000</Price> 


  ABC Industries
  agrees to lease the property at
  123 Main St., Chicago, IL
  XYZ Properties
  for a term of not less than
  at a cost of

This is why I find your question confusing :)

I hope that this helps anyway,


Jeni Tennison

 XSL-List info and archive:

Current Thread