Re: ResultTreeFrag to String

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

>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:for-each>
  <xsl:text>&gt;</xsl:text>
  <xsl:apply-templates />
  <xsl:value-of select="concat('&lt;/', name(), '&gt;')" />
</xsl:template>

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:

  <Lease>
  <Lessee>ABC Industries</Lessee> 
  agrees to lease the property at 
  <Address>123 Main St., Chicago, IL</Address> 
  from 
  <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> 
  . 
  </Lease>

is

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

This is why I find your question confusing :)

I hope that this helps anyway,

Jeni

Jeni Tennison
http://www.jenitennison.com/


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


Current Thread