This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: : How to handle two XML sources in one style sheet
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl]: How to handle two XML sources in one style sheet
- From: "Paul Tyson" <paul at precisiondocuments dot com>
- Date: Mon, 1 Oct 2001 22:05:35 -0700
- Organization: Precision Documents
- References: <000001c14aaa$e770ce30$2100a8c0@swiftnet.tec>
- Reply-To: xsl-list at lists dot mulberrytech dot com
"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) = '<'">
<xsl:variable name="gi"
select="substring-after(substring-before($xml-string,'>'),'<')"/>
<xsl:element name="{$gi}">
<xsl:call-template name="xml2rtf">
<xsl:with-param name="xml-string"
select="substring-after(
substring-before(
$xml-string,concat('</',$gi,'>')),'>')"/>
</xsl:call-template>
</xsl:element>
<xsl:call-template name="xml2rtf">
<xsl:with-param name="xml-string"
select="substring-after(
$xml-string,concat('</',$gi,'>'))"/>
</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