Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping over specific nodes within a stupid XML document 1

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Hi,

We are calling a webservice from asp.net and we are getting an XML document returned. We want to process this document into html using xslt. The document is to do with a shopping cart, and we have got a parent node called CartResults and then child nodes called lineItems and SubLineItems. Structuredd like this:

<CartResults>
<lineItems>
<id>1</id>
</lineItems>
<lineItems>
<id>2</id>
</lineItems>
<subLineItems>
<id>1</id>
</subLineItems>
<subLineItems>
<id>1</id>
</subLineItems>
<subLineItems>
<id>1</id>
</subLineItems>
<subLineItems>
<id>2</id>
</subLineItems>
<subLineItems>
<id>2</id>
</subLineItems>
</CartResults>

What I have at the moment is a loop to loop over all of the lineitems within the document, but when looping over these lineitems I need to be able to find the related sublineitems from within the document. The lineitems and the sublineitems are related via the id element. so when looping over the lineitem ID=1 I need to find the related sublineitems with an id of 1 as well and output them.

this is the what i have at the moment, but i can't help thinking that there is an easier way of doing this:

Code:
<xsl:for-each select="//LineItem">
 <tr>
  <td valign="top"><xsl:call-template name="Description"><xsl:with-param name="id" select="id" /></xsl:call-template></td>
 </tr>
</xsl:for-each>
</xsl:template>

 <xsl:template name="Description">
  <xsl:param name="id" />
 
  <xsl:for-each select="//SubLineItem">
    <xsl:if test="$id = id">
     -- output data -- 
    </xsl:if>
  </xsl:for-each>

hope this makles sense to someone out there

TIA

Tony
 
Code:
<xsl:for-each select="//LineItem">
  <tr>
    <td valign="top">
      <xsl:for-each select="../SubLineItem[id = current()/id]">
        -- output data --
      </xsl:for-each>
    </td>
  </tr>
</xsl:for-each>

Jon

"I don't regret this, but I both rue and lament it.
 
Jon,

Thanks for the info, worked a charm

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top