[xsl] X-referencing (grouping? variables? keys?)

Subject: [xsl] X-referencing (grouping? variables? keys?)
From: Clay Leeds <cleeds@xxxxxxxxxx>
Date: Fri, 18 Oct 2002 10:24:55 -0700
Howdy,

I display RCs and TRCs in each line of my DETAIL section, then give the corresponding RC & TRC Explanations in an EXPLANATION section below, only if they display. If there's no RC, nothing should display in either location. If there's a TRC, it supercedes the RC, and its RC Explanation should not display. When all is said and done, the RC Explanation section should display RC Explanations for all RCs which displayed, and the TRC Explanation section should display Explanations of all TRCs which displayed.

I thought of using ARRAYs for this, then learned that XSL has no "array" functionality. So I thought I'd stuff all displayed values into an XSL:VARIABLE or XSL:PARAMETER. Then I'd do some magic to make certain the VAR/PARAM only contained unique values. I'd like to select *all* items which match the result (similar to the display shown by the excellent XPATH Visualizer), and put/concatenate them into one variable. Unfortunately, the only way I've been successful is with some xsl:for-each statement, although this just puts them all into a document instead of into a variable. Unfortunately, given the following XSL, the result is only *the first* element returned:

<xsl:variable name="VARALLRCS" select="//TRC[.='']/preceding-sibling::*[.!='']/text()">
<xsl:variable name="VARALLTRCS" select="//RC[.!='']/following-sibling::*[.!='']/text()">


This puts all values into the document, but I don't know how to make use of that. I thought of creating some sort of Result Tree Fragment, but I don't know how to access that either.

<xsl:for-each select="//RCDATALINE">
  <xsl:if test="RC[.!=''] and TRC[.='']">
    <xsl:value-of select="RC/text()"/>
  </xsl:if>
</xsl:for-each>

In a more recent brainstorm, I came up with this, but it appears to overwrite the value each time it goes through, and I end up with just 'New RCVALUE(s)=' (I've tried it without a value, as well).

  <xsl:param name="RCVALUE" select="'New RCVALUE(s)='">
    <xsl:for-each select="//RCDATALINE">
      <xsl:if test="RC[.!=''] and TRC[.='']">
        <xsl:value-of select="concat($RCVALUE, RC/text())"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:param>
  <xsl:param name="TRCVALUE" select="'New TRCVALUE(s)='">
    <xsl:for-each select="//RCDATALINE">
      <xsl:if test="RC[.!=''] and TRC[.!='']">
        <xsl:value-of select="concat($TRCVALUE, TRC/text())"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:param>

Any ideas?

INPUT XML FRAGMENT:
===================
<DETAIL>
  <DETAILLINE>
    <PRODUCT>00201</PRODUCT>
    <RCDATA>
      <RCDATALINE>
        <RC></RC>
        <TRC>03</TRC>
      </RCDATALINE>
      <RCDATALINE>
        <RC>01</RC>
        <TRC>42</TRC>
      </RCDATALINE>
      <RCDATALINE>
        <RC></RC>
        <TRC></TRC>
      </RCDATALINE>
    </RCDATA>
  </DETAILLINE>
  <DETAILLINE>
    <PRODUCT>00202</PRODUCT>
    <RCDATA>
      <RCDATALINE>
        <RC>01</RC>
        <TRC>R3</TRC>
      </RCDATALINE>
      <RCDATALINE>
        <RC>02</RC>
        <TRC>R1</TRC>
      </RCDATALINE>
      <RCDATALINE>
        <RC>04</RC>
        <TRC>R4</TRC>
      </RCDATALINE>
       <RCDATALINE>
        <RC>05</RC>
        <TRC></TRC>
      </RCDATALINE>
   </RCDATA>
  </DETAILLINE>
</DETAIL>
<RCINFO>
  <RCHEADER>RC Explanations:</RCHEADER>
  <RCLINE>
    <RCCODE>RC 01</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>RC 02</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>RC 04</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>RC 05</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
</RCINFO>
<TRCINFO>
  <RCHEADER>TRC Explanations:</RCHEADER>
  <RCLINE>
    <RCCODE>TRC 03</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>TRC 42</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>TRC R1</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>TRC R3</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
  <RCLINE>
    <RCCODE>TRC R4</RCCODE>
    <RCEXPLANATION>
      <LINE>1st line info</LINE>
      <LINE>2nd line info</LINE>
      <LINE>3rd line info</LINE>
    </RCEXPLANATION>
  </RCLINE>
</TRCINFO>
===================


CURRENT INPUT XSL:
==================
<xsl:template name="TMPALLRCVALUES">
<xsl:param name="RCVALUE" select="'New RCVALUE(s)='">
<xsl:for-each select="//RCDATALINE">
<xsl:if test="RC[.!=''] and TRC[.='']">
<xsl:value-of select="concat($RCVALUE, RC/text())"/>
</xsl:if>
</xsl:for-each>
</xsl:param>
<xsl:param name="TRCVALUE" select="'New TRCVALUE(s)='">
<xsl:for-each select="//RCDATALINE">
<xsl:if test="RC[.!=''] and TRC[.!='']">
<xsl:value-of select="concat($TRCVALUE, TRC/text())"/>
</xsl:if>
</xsl:for-each>
</xsl:param>
<fo:block font-family="courier new, courier, monospace" font-size="8pt" padding-top="2pt" padding-bottom="2pt" padding-left="6pt">
<fo:block>
Template TMPALLRCVALUES:
</fo:block>
<fo:block>
<xsl:value-of select="$RCVALUE"/>
</fo:block>
<fo:block>
<xsl:value-of select="$TRCVALUE"/>
</fo:block>
<!--xsl:param name="TRCVALUE"/>
<xsl:for-each select="//RCDATALINE">
<xsl:param name="RCVALUE" select="concat($RCVALUE,RC)"/>
<xsl:param name="TRCVALUE" select="concat($TRCVALUE,TRC)"/>
<fo:block font-family="courier new, courier, monospace" font-size="8pt" padding-top="2pt" padding-bottom="2pt" padding-left="6pt" color="#FF00FF">
<xsl:value-of select="$RCVALUE"/>
</fo:block>
<fo:block font-family="courier new, courier, monospace" font-size="8pt" padding-top="2pt" padding-bottom="2pt" padding-left="6pt" color="#00FFFF">
<xsl:value-of select="$TRCVALUE"/>
</fo:block>
</xsl:for-each-->
</fo:block>
</xsl:template>
==================


DESIRED OUTPUT
==============
DETAILS:
00201           42
00202           R3 R1 R4 05

RC Explanations:
  05    1st line info 2nd line 3rd line info

RC Explanations:
  42    1st line info 2nd line 3rd line info
  R1    1st line info 2nd line 3rd line info
  R3    1st line info 2nd line 3rd line info
  R4    1st line info 2nd line 3rd line info
==============

BTW, forgive my ignorance, but I don't really know what SUBJECT to put for this POST.

Thanks for the help!

- Clay Leeds
- Web Developer/Programmer
- cleeds@xxxxxxxxxx


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread