[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: : How to handle two XML sources in one style sheet
From: "Paul Tyson" <paul@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 1 Oct 2001 22:05:35 -0700
xml2rtf
"Chris Bayes" <chris@xxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxxxx              http://precisiondocuments.com
     "The art and science of document engineering."




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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.