[xsl] using Xpath predicate to filter source nodes in called templates

Subject: [xsl] using Xpath predicate to filter source nodes in called templates
From: "Chris Pearson" <chrisp@xxxxxxxxxxx>
Date: Fri, 11 Jan 2002 13:25:57 -0500
Hello list,

I have an xml source with 3 hierarchical levels. (anyone familiar with EDI will recognize element names...)  However, within this structure, there are implied loops.  An <ISA> element is closed by an <IEA> element, a <GS> element is closed by a <GE> element, a <ST> element is closed by an <SE> element.  Within the <ST> the <LIN> may loop repeatedly, and within the <LIN> the <FST> may loop repeatedly.

I'm trying the following, but I'm getting ALL LINs/FSTs for the first, then all but the first LINs/FSTs for the second, then all but the first and second LINs/FSTs for the third and so on..  Anyone got any suggestions?

Thanks,
Chris

The XSLT is:
<xsl:template name="ST">
<xsl:param name="param1"/>
<xsl:for-each select="../ST[preceding-sibling::GS/GS1=$param1]">
  <!-- write the elements associated with the ST before calling LIN template-->
  <xsl:call-template name="LIN">
    <xsl:with-param name="param2" select="ST/ST1"/>
  </xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="LIN">
<xsl:param name="param1"/>
<xsl:param name="param2"/>
<xsl:for-each select="../LIN[preceding-sibling::ST/ST1=$param1]">
  <!-- write the elements associated with the LIN before calling FST template-->
  <xsl:call-template name="FST">
    <xsl:with-param name="param3" select="LIN/LIN1"/>
  </xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="FST">
<xsl:param name="param1"/>
<xsl:param name="param2"/>
<xsl:param name="param3"/>
<xsl:for-each select="../FST[preceding-sibling::LIN/LIN1=$param2][preceding-sibling::ST/ST1=$param1]">
  .. do stuff for each FST element ..
</xsl:for-each>
</xsl:template>

The XML structure:
<root>
  <ISA>
    <ISA1 />
    <ISAn />
  </ISA>
  <GS>
    <GS1 />
    <GSn />
  </GS>
  <ST>
    <ST1 />
    <STn />
  </ST>
  <LIN> <!-- May repeat within ST elements-->
    <LIN1 />
    <LINn />
  </LIN>
  <FST> <!-- May repeat within LIN elements -->
    <FST1 /
    <FSTn />
  </FST>
  <SHP>
    <SHP1 />
    <SHPn />
  </SHP>
  <SE>
    <SE1 />
    <SEn />
  <GE>
    <GE1 />
    <GEn />
  </GE>
 <IEA>
    <IEA1 />
    <IEAn />
  </IEA>  
</root>



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


Current Thread