[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: in-document references
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: [snip]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>
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>
<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: 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 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|