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

Re: in-document references

Subject: Re: in-document references
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 7 Jan 2003 14:28:47 +0000
flatten schema xsl
Hi Simon,

> I'm not sure if the word "flatten" was right. I want it to expand all 
> of the defines so that everywhere there is a "ref" it is replaced by 
> whatever is in the "define". I could pre-process the file with XSLT 
> that does that, but I'd rather skip that step since it could result in 
> a potentially very large intermediate file.

You would also run into difficulties if you ever tried to flatten a
schema for documents with a recursive structure, e.g.:

<define name="section">
  <element name="section">
    <oneOrMore>
      <ref name="paragraph" />
    </oneOrMore>
    <zeroOrMore>
      <ref name="section" />
    </zeroOrMore>
  </element>
</define>

but perhaps that won't occur in the kind of XML that you're dealing
with.

>From the sounds of it, you want to access the most recent
element/attribute element in the template for the <data> element. To
do that consistently through multiple <ref>s and <define>s, you need
to pass it as a parameter. Something like:

<xsl:key name="defines" match="rng:define" use="@name" />

<xsl:template match="rng:element">
  ...
  <xsl:apply-templates>
    <xsl:with-param name="node" select="." />
  </xsl:apply-templates>
  ...
</xsl:template>

<xsl:template match="rng:ref">
  <xsl:param name="node" />
  <xsl:apply-templates select="key('defines', @name)">
    <xsl:with-param name="node" select="$node" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="rng:define">
  <xsl:param name="node" />
  <xsl:apply-templates>
    <xsl:with-param name="node" select="$node" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="rng:data">
  <xsl:param name="node" />
  <xsl:value-of select="$node" />
</xsl:template>

You could pass the <ref> element through to the template for the
<define> element, but you'll start losing track of what the context is
if you go through multiple <ref>s on your way from an <element> to a
<data> element.

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.