xsl-list
[Top] [All Lists]

Re: [xsl] Referencing XML fragments in a XSLT parameter?

2007-01-29 07:00:17
Hi Stephan,

You can declare a variable in your stylesheet and use it, you can set it from your Java code to a DOM. If you don't need to do any changes to the input, you can use the xsl:copy-of instruction.

<xsl:param name="first-input" required="yes" />
<xsl:param name="second-input" required="yes" />

<xsl:template match="/" >
   <xsl:copy-of select="$first-input/bookselection/book" />
   <xsl:copy-of select="$second-input" />
</xsl:template>

However, if you do want some changes, you can simply use apply-templates:
<xsl:apply-templates select="$first-input/*" />

Be aware of namespaces, though (if your in-memory objects use namespaces, make sure to use them in you templates as well).

Cheers,
-- Abel






stephan(_at_)wissel(_dot_)net wrote:
I have an application that produces 2 DOM documents in (Java) memory, that need to be processed in an XSLT transformation. I used the first as input source for the transformation and was wondering how to get the second into the picture. It is rather small with 20-30 nodes only. Since it is generated in code it doesn't have an URL, so document() will not work (?). I could pass the dom into a param, but how to reference it?

The first input looks like:

  <bookselection>
        <category>Sience Fiction</category>
        <book>
            <title>Solaris</title>
            <author>Lem</author>
        </book>
        <book>
            <title>Sheep look up</title>
            <author>Brunner</author>
        </book>
    </bookselection>

The second one looks like

 <categories>
        <category>Sience Fiction</category>
        <category>Cooking</category>
        <category>Horror</category>
    </categories>

What I need to achive is:
<books>
        <categories>
            <category selected="true">Sience Fiction</category>
            <category>Cooking</category>
            <category>Horror</category>
        </categories>
        <book>
            <title>Solaris</title>
            <author>Lem</author>
        </book>
        <book>
            <title>Sheep look up</title>
            <author>Brunner</author>
        </book>
    </books>

XSLT 2.0 would be OK. Help is greatly appreciated.
:-) stw

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>