xsl-list
[Top] [All Lists]

Re: numbering and sorting compatibility issue

2003-03-22 07:52:40
Hi Andrew,

OK I'll be more concrete,
I've following structure
<Report>
<Manufacturing m_no="1">
    <Order code="x">
        <Equipment name="y">
            <Element part="z" qty="3"/>
            <Element part="z" qty="4"/>
            ...
        </Equipment>
        <Equip...
    </Order>
    <Order...
</Manufacturing>
<Manufact...
</Report>
I think self describing...
[snip]
so I need to sort Elements by "part" AND number through all "Report"
but I do numbering in "Equipment" context/template so...

I think from your description that you want the following. The
numbering is generated by taking the position() in the *sorted* list
within a particular <Equipment> element, and adding it to the number
of <Element> elements that appeared before the particular <Equipment>
element.

<xsl:template match="Manufacturing">
  <tr><td>Manufacturing No <xsl:value-of select="@m_no" /></td></tr>
  <xsl:apply-templates select="Order" />
</xsl:template>

<xsl:template match="Order">
  <tr><td>Order <xsl:value-of select="@code" /></td></tr>
  <xsl:apply-templates select="Equipment" />
</xsl:template>

<xsl:template match="Equipment">
  <tr><td>Equipment <xsl:value-of select="@name" /></td></tr>
  <xsl:for-each select="Element">
    <xsl:sort select="@part" />
    <tr>
      <td>
        <xsl:value-of
          select="position() +
                  count(../Equipment/preceding::Element)" />
      </td>
      <td>Element </td>
      <td><xsl:value-of select="@qty" /></td>
    </tr>
  </xsl:for-each>
</xsl:template>

but it's hard to tell. If this isn't what you want, I suggest you
provide a longer sample XML document (including several <Element>
elements with different part attributes, in different <Equipment>
elements) and some sample output that you want generated from it.
Providing the XSLT that you've tried and that isn't working would help
as well.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



<Prev in Thread] Current Thread [Next in Thread>