I've never heard of tunneling, but it worked. Thanks!
I think the hard part about learning XSLT is not knowing what terms to
google when searching for a solution, especially for the more complex
concepts. There are plenty of good references available if you know what
you want. Personally, I find the spec very hard to use as a reference
document.
Thanks, again!
Angela
-----Original Message-----
From: Wendell Piez [mailto:wapiez(_at_)mulberrytech(_dot_)com]
Sent: Tuesday, March 20, 2007 5:54 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] xpath / multiple context question
Dear Angela,
Please forgive me if I'm not fully grasping your requirement.
Couldn't you address this by processing not the element to which your
XPath points, but its closest data-value ancestor, as in
<xsl:variable name="amt-source"
select="$node/sax:evaluate(substring-after($field,
concat($rows,'/')))/ancestor::data-value[1]" mode="display"/>
and then
<xsl:apply-template select="$amt-source">
<xsl:with params ... /><!-- passing in your precision, etc. -->
</xsl:apply-templates>
<xsl:template match="xpath" mode="display">
<xsl:param name="precision" .../>
<xsl:value-of select="fc:nbr-format(number(.),$precision,'true','$')"
/>
</xsl:template>
... with more templates to match your formatting markup?
You might want to use the XSLT 2.0 tunneling parameters feature, if
you can. Otherwise just make sure that any templates in the "display"
mode pass the parameter(s) correctly.
I hope that's somewhat on track, or at least sparks your thinking.
Cheers,
Wendell
At 06:22 PM 3/20/2007, you wrote:
fruit-layout.xml:
<?xml version="1.0" encoding="UTF-8"?>
<table>
<data-set>
<row-set xpath="doc('fruit-data.xml')/a/b" />
<order-by xpath="doc('fruit-data.xml')/a/b/c" />
</data-set>
<columns>
<column>
<format>
<type>currency</type>
<precision>2</precision>
<show-sign>first-and-last</show-sign>
</format>
<data-value>
<bold>
<xpath>doc('fruit-data.xml')/a/b/d</xpath>
</bold>
</data-value>
</column>
</columns>
</table>
fruit.xsl (abbreviated)
<xsl:stylesheet exclude-result-prefixes="#all"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fc="http://www.myfruit.com/fruit"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sax="http://saxon.sf.net/"
version="2.0">
<snip>
<xsl:template match="columns">
<xsl:variable name="cols" select="." /> <!-- outer context -->
<xsl:variable name="rows" as="xs:string">
<xsl:value-of select="../data-set/row-set/@xpath" />
</xsl:variable>
<xsl:variable name="sort" as="xs:string">
<xsl:value-of select="../data-set/order-by/@xpath" />
</xsl:variable>
<xsl:for-each select="sax:eval(sax:expression($rows))">
<xsl:sort
select="sax:eval(sax:expression(substring-after($sort,
concat($rows, '/'))))" />
<xsl:variable name="node" select="." /> <!-- data element
context -->
<tr>
<xsl:for-each select="$cols/column">
<td><p>
<xsl:variable name="field"> <!-- value context -->
<xsl:value-of select="data-value/descendant::xpath" />
</xsl:variable>
<xsl:variable name="amt" as="xs:string"
select="$node/sax:evaluate(substring-after($field,
concat($rows,'/')))" />
<xsl:variable name="precision" as="xs:integer">
<logic />
</xsl:variable>
<!-- The following line produces the child data value.
How do I wrap this with the parent <b> element? -->
<xsl:value-of
select="fc:nbr-format(number($amt),$precision,'true','$')" />
</p></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="bold">
<b>
<xsl:apply-templates />
</b>
</xsl:template>
<xsl:template match="xpath">
<!-- This is where I need the child data value to print in the
result tree.
If I just match here, I lose the context and get ALL xpath
values, when
I only want the formatted child data value resolved in the
columns template.
?????
-->
</xsl:template>
</snip>
</xsl:stylesheet>
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--