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

RE: XML fragment as a param ?

Subject: RE: XML fragment as a param ?
From: "Nick Fitzsimons" <nick@xxxxxxxxxxxxxx>
Date: Thu, 3 Nov 2005 12:34:24 -0000 (GMT)
nick fitzsimons
>>>>>>"Fraser" == Fraser Goffin <goffinf@xxxxxxxxxxx> writes:

> Fraser> Is it possible to pass in an XML fragment as a param and then
> Fraser> access nodes
> Fraser> in the fragment as well as those in the main source instance
>
> Michael>Yes. The way you pass the value depends of course on your
> processor
> API.
>
> Michael, not sure what you mean, I'm using Xerces/Xalan if that helps ?
>

I'm not certain how Xalan handles this, but the general technique is:

get your XSLT processor, configured with your stylesheet and input XML
document;
get your XML fragment (probably by selecting a node from a DOMDocument, or
if it's text, by having it parsed into a DOMDocument);
add it as a parameter to the processor (MSXML uses "addParameter"; Xalan's
processor class will have a similar method);
access it via the parameter in your stylesheet.

In pseudocode:

processor = getProcessor(yourStylesheet);
processor.input = inputXMLDocument;
processor.output = outputXMLDocument;
processor.addParameter("myXMLFragment", supplementaryXML);
processor.transform();

Within your stylesheet you will have the parameter declared, and access
the content of the fragment via that:

<xsl:stylesheet>
   <xsl:param name="xmlFragment" select="/.." />

   <!-- later... -->

   <xsl:template match="some/node/in/main/document">
      <!-- get a heading from the XMl fragment passed in -->
      <h1><xsl:value-of select="$xmlFragment/supplementary/heading" /></h1>
   </xsl:template>

   <!-- lots of other stuff... -->

</xsl:stylesheet>

How you actually implement the above in real-life code depends on your
processor, so check the Xalan docs for a function with a name similar to
"addParameter", or google for a tutorial.

The procedure for using the "document()" function is different to this,
and "data:" URIs are a different kettle of fish altogether, but as you
originally asked about passing the fragment in a param, this will
hopefully point you in the right direction.

HTH,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/

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-2013 All Rights Reserved.