|
Subject: Re: [xsl] xpath / multiple context question From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 20 Mar 2007 18:54:03 -0400 |
<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>
Cheers, Wendell
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@xxxxxxxxxxxxxxxx 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 ======================================================================
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] xpath / multiple context ques, Angela Williams | Thread | RE: [xsl] xpath / multiple context , Angela Williams |
| [xsl] xpath / multiple context ques, Angela Williams | Date | [xsl] Set difference in xsl:number/, Deborah Pickett |
| Month |