This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: : How to handle two XML sources in one style sheet


"Chris Bayes" <chris@bayes.co.uk> wrote on
Monday, October 01, 2001 11:57 AM


> Woohh,
> You really don't want them as strings. You really want to pass a dom as
> an object and then use that in the transform.
>

I might want to, especially if I want all of my processing intelligence in
my XSLT stylesheet, or if I can't spell DOM.

Consider the following template:

  <xsl:template name="xml2rtf">
    <!-- This template parses a *simple* XML string and returns a result
         tree fragment.  MINIMAL PARSING capabilities are demonstrated:
         no attributes or whitespace allowed in begin/end tags;
         no mixed content in elements.
         Adding these features are 'exercises for the reader'
         -->
    <xsl:param name="xml-string"/>
    <xsl:choose>
      <xsl:when test="not($xml-string)"/>
      <xsl:when test="substring($xml-string,1,1) = '&lt;'">
        <xsl:variable name="gi"

select="substring-after(substring-before($xml-string,'&gt;'),'&lt;')"/>
        <xsl:element name="{$gi}">
          <xsl:call-template name="xml2rtf">
            <xsl:with-param name="xml-string"
              select="substring-after(
                      substring-before(
                      $xml-string,concat('&lt;/',$gi,'&gt;')),'&gt;')"/>
          </xsl:call-template>
        </xsl:element>
        <xsl:call-template name="xml2rtf">
          <xsl:with-param name="xml-string"
            select="substring-after(
                    $xml-string,concat('&lt;/',$gi,'&gt;'))"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$xml-string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

When called like so:

<xsl:variable name="xml-rtf">
    <xsl:call-template name="xml2rtf">
        <xsl:with-param name="xml-string" select="$xml-param"/>
    </xsl:call-template>
 </xsl:variable>

will bind $xml-rtf to a result tree fragment of the parsed XML parameter.

You can then either:
    1. Use the value-of $xml-rtf (probably not very useful because it
reduces to the concatenated string values of the nodes).
    2. Use a copy-of $xml-rtf in your XML output.
    3. Apply a node-set (extension) function to $xml-rtf, and then apply or
call templates for further processing.

This technique could be particularly useful for passing parameters to an
XSLT process on a web server, especially when used in conjunction with a
client-side javascript to compose form data into an XML string.

Enjoy,

Paul Tyson, Principal Consultant                   Precision Documents
paul@precisiondocuments.com              http://precisiondocuments.com
     "The art and science of document engineering."




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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]