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

Re: Dynamicly Generate a apply-templates match pattern

Subject: Re: Dynamicly Generate a apply-templates match pattern.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Aug 2004 09:46:07 +0100
apply templates match
Hi Peter,

> I would like to be able to transform my html template so that the
> match attribute of my rui:insert element is used to generate an
> apply-templates select statement.
>
> The template would be something like this:
>
>  <xsl:template match="rui:insert">
>    <xsl:apply-templates select="$content/@match"/>
> 	</xsl:template>

You can't do this in XSLT. What you can do, however, is create an XSLT
stylesheet that uses your HTML template to create an XSLT stylesheet
that, when run over your content, generates the output you want.
Diagrammatically:

                 generator
                 stylesheet
                     |
                     v
  html template -- (XSLT) -->  stylesheet
                                   |
                                   v
                      content -- (XSLT) --> result

The generator stylesheet would look something like:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/XSL/TransformAlias"
                xmlns:rui="user.interface"
                exclude-result-prefixes="rui">

<xsl:namespace-alias stylesheet-prefix="#default"
                     result-prefix="xsl" />

<!-- create a styelsheet -->
<xsl:template match="/">
  <stylesheet version="1.0">
    <template match="results">
      <xsl:apply-templates />
    </template>
    <include href="main.xsl" />
  </stylesheet>
</xsl:template>

<!-- copy everything by default -->
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

<!-- insert <xsl:apply-templates> instructions in place of
     <rui:insert> elements -->
<xsl:template match="rui:insert">
  <apply-templates select="{@match}" />
</xsl:template>

</xsl:stylesheet>

Running this over your html template should generate something like:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="results">
  <html>
    <header>
      <xsl:apply-templates select="pageDisplayName" />
    <header>
    <body>
      <xsl:apply-templates select="document('header.xml')" />
    </body>
  </html>
</xsl:template>

<xsl:include href="main.xsl" />

</xsl:stylesheet>

main.xsl should contain the templates for processing the
<pageDisplayName> element and the other elements that appear within
the <results> document.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.