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

Re: XSLT 2.0 question

Subject: Re: XSLT 2.0 question
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 18 Mar 2002 09:35:30 +0000
Re:  XSLT 2.0 question
Hi Bryan,

> am wondering if it would be possible to set up solutions that do the
> following in xslt 2.0, let us say you run your xslt against an xml
> document that contains inline xslt code, perhaps just a single
> xsl:template, would there be any way, hopefully incredibly involved
> and complex :) to declare that inline templates should be run and
> take precedence over templates in the xslt.

Yep, they're called embedded stylesheets. See
http://www.w3.org/TR/xslt#section-Embedding-Stylesheets in XSLT 1.0 or
http://www.w3.org/TR/xslt20/#embedded in the XSLT 2.0 WD.

Say that your stylesheet was called 'stylesheet.xsl', you could do:

<doc>
  <person>...</person>
  
  <xsl:stylesheet version="1.0" id="stylesheet"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                  
    <xsl:import href="stylesheet.xsl" />
    
    <xsl:template match="person">
      do something
    </xsl:template>

  </xsl:stylesheet>
</doc>

If you use the embedded stylesheet (accessing it by its ID), then it
imports your main stylesheet (stylesheet.xsl) and overrides its
content in just the same way as importing a stylesheet does normally.
So your local style information for the person element has priority.

To make this work, you have to declare the id attribute on
xsl:stylesheet as an ID attribute, so the top of the document will
probably actually look like:

<?xml version="1.0"?>
<!DOCTYPE doc [
<!ELEMENT xsl:stylesheet ANY>
<!ATTLIST xsl:stylesheet id ID #REQUIRED>
]>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<doc>
  <person>...</person>
  
  <xsl:stylesheet version="1.0" id="stylesheet"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                  
    <xsl:import href="stylesheet.xsl" />
    
    <xsl:template match="person">
      do something
    </xsl:template>

  </xsl:stylesheet>
</doc>

Cheers,

Jeni

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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.