Re: [xsl] xpath / multiple context question

Subject: Re: [xsl] xpath / multiple context question
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Mar 2007 18:54:03 -0400
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:template match="xpath" mode="display">
  <xsl:param name="precision" .../>
  <xsl:value-of select="fc:nbr-format(number(.),$precision,'true','$')" />

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


At 06:22 PM 3/20/2007, you wrote:
<?xml version="1.0" encoding="UTF-8"?>
    <row-set xpath="doc('fruit-data.xml')/a/b" />
    <order-by xpath="doc('fruit-data.xml')/a/b/c" />

fruit.xsl (abbreviated)
<xsl:stylesheet exclude-result-prefixes="#all"


  <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 name="sort" as="xs:string">
      <xsl:value-of select="../data-set/order-by/@xpath" />

<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 -->
        <xsl:for-each select="$cols/column">

            <xsl:variable name="field">  <!-- value context -->
              <xsl:value-of select="data-value/descendant::xpath" />

<xsl:variable name="amt" as="xs:string" select="$node/sax:evaluate(substring-after($field, concat($rows,'/')))" />

              <xsl:variable name="precision" as="xs:integer">
                <logic />

<!-- 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','$')" />


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


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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