|
[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
"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) = '<'"> <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@xxxxxxxxxxxxxxxxxxxxxx http://precisiondocuments.com "The art and science of document engineering." XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






