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

Re: processing code embedded inside a stylesheet

Subject: Re: processing code embedded inside a stylesheet
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Apr 2004 10:29:35 -0400
processing code
Hi Jeffrey,

The basic answer to your question is "no, not in XSLT 1.0", but there's an "except".

The "except" depends on whether:

* your processor supports a node-set() extension function (which creates a node set from a result-tree-fragment), and

* whether you are able and willing to use it.

If you are, you can do this:

<xsl:template match="template:defaultpage">
  <xsl:variable name="contents">
    <!-- build an RTF containing the nodes we want to process -->
    <template:header title="Hello World" />
    <template:body>
      <xsl:apply-templates />
    </template:body>
  </xsl:variable>

  <html>
    <!-- convert the RTF into a node set and process it -->
    <xsl:apply-templates select="exsl:node-set($contents)/*"/>
  </html>
</xsl:template>

Note:

* I'm using "exsl" as the namespace prefix here for the extension function (though I haven't shown a declaration for it). You will use whatever works. (Check xsltproc's documentation: I think it supports this function in the EXSLT namespace.)

* You have to have the extra step "/*" on that XPath because if you don't, your new node set will be processed first by matching its root node, which will match your root node template as if it was the root node of your source document -- not what you want. (Another and possibly safer way of doing this would be to use a different mode.)

* This is very dangerous, not because it won't work, but because your head may explode. (In your case I wouldn't worry too much, given how you've figured out this *might* be possible ... but I'd worry about any poor XSLT maintainer who comes after you.)

Good luck,
Wendell

At 06:49 PM 4/13/2004, you wrote:
I have a number of templates that are all recursed using a simple
<xsl:apply-templates /> within all the templates, its for processing XHTML.

I want to put some nodes to match inside another template, for example:

<xsl:template match="template:header">
 <head>
  <title><xsl:value-of select="@title" /></title>
 </head>
</xsl:template>

<xsl:template match="template:body">
 <body>
  <xsl:apply-templates />
 </body>
</xsl:template>

now I want to do:

<xsl:template match="template:defaultpage">
<html>
 <template:header title="Hello World" />
 <template:body>
  <xsl:apply-templates />
 </template:body>
</html>
</xsl:template>


Is there a way to tell xsltproc to process these nodes as if they were part of the source file?


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

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.