[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: S Woodside <sbwoodside@xxxxxxxxx>
Date: Mon, 6 Jan 2003 19:41:07 -0500
define b
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.

On Monday, January 6, 2003, at 06:51 PM, Martinez, Brian wrote:

From: S Woodside [mailto:sbwoodside@xxxxxxxxx]
   <xsl:template match="ref">
     <li>Ref:
       <b><xsl:value-of select="@name"/></b>
       <ul>
         <xsl:apply-templates
               select="//define[@name=current()/@name]"
               mode="def"/>
       </ul>
     </li>
   </xsl:template>
[snip]

Your current select expression tells the processor to select all 'define'
nodes that are descendants of the document element.

That's what I want to do. Here's a complete example:



=============data.xml==================


<!--This is a Relax NG schema-->
<grammar>
	<element name="Id">
			<ref name="string"/>
	</element>
	<define name="string">
			<data type="string"/>
	</define>
</grammar>


=============form.xsl==================


[...]

  <xsl:template match="element">
    <li>Element:
          <xsl:value-of select="@name"/>
          <ul>
            <xsl:apply-templates/>
          </ul>
    </li>
  </xsl:template>

 <xsl:template match="ref">
    <li>Ref:
      <b><xsl:value-of select="@name"/></b>
      <ul>
        <xsl:apply-templates
              select="//define[@name=current()/@name]"
              mode="def"/>
      </ul>
    </li>
  </xsl:template>

  <xsl:template match="define" mode="def">
    <xsl:apply-templates/>
  </xsl:template>

<xsl:template match="data">
<li>
<xsl:value-of select="ancestor-or-self::element[@name][1]/@name"/>
</li>
</xsl:template>


<!--This rule is just to kill the defines when they are encountered later-->
<xsl:template match="define">
<li>[Define:
<b><xsl:value-of select="@name"/></b>]
</li>
</xsl:template>



==================output should be=============== (ignoring whitespace issues)

<li>Element: Id
    <ul>
      <li>Ref: <b>string</b>
        <ul>
          <li>
                 Id   <!--This is the hard part-->
          </li>
	  </ul>
    </ul>
</li>
<li>
  [Define: <b>string</b>]
</li>

=================what I get right now================

<li>Element: Id
    <ul>
      <li>Ref: <b>string</b>
        <ul>
          <li>
                 <!--I get nothing here since there is no "element"
                   parent of "define" in the data-->
          </li>
	  </ul>
    </ul>
</li>
<li>
  [Define: <b>string</b>]
</li>

To select just
descendants of the context node, do:

<xsl:apply-templates select=".//define[@name=current()/@name]" mode="def"/>

The problem is that the "context" of the context node includes the ancestor elements and so on, which I wish to access from <xsl:template match="define">. Does that make sense?


(This doesn't address optimization of course--this search pattern can be
quite expensive.)

I can live with that, I'm using AxKit and static data.


simon

---
www.simonwoodside.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.