This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: for-each: is there a better way to do this?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] for-each: is there a better way to do this?
- From: Amy Kaizerman <amy dot j dot kaizerman at lmco dot com>
- Date: Mon, 29 Oct 2001 18:23:37 -0800
- References: <8900656CF898D111B75700805FE66A761096C82A@aupoza438.btal.btco.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Very cool! Thanks! I'll try it out tomorrow.
Amy
Joshua.Kuswadi@BTFinancialgroup.com wrote:
> Amy wrote:
> > Hi! I'm still trying to figure things out and wanted to ask if there
> > was a better way to
> > build my stylesheet. I'm using for-each a lot and it seems like I
> > should be using apply-templates
> > more, but I'm just not sure how to do that. I would greatly
> > appreciate
> > any help given.
>
> <snip> XML and XSL sample code cut out </snip>
>
> >From what I've tried (and read), the use of apply-templates is much preferred over for-each. It looks like your stylesheet has three natural looking templates to come out of it. So a (simplified) stylesheet for you may be:
>
> <xsl:stylesheet>
> <xsl:output method="html" indent="yes" />
>
> <xsl:template match="/">
> <xsl:apply-templates select="Aps:VpmResultSet/Aps:PartStructure" />
> </xsl:template>
>
> <xsl:template match="Aps:VpmResultSet/Aps:PartStructure">
> <xsl:apply-templates select="Aps:AsDesigned/Aps:Drawing" />
> <xsl:apply-templates select="Aps:AsDesigned/Aps:Specification" />
> <xsl:apply-templates select="Aps:AsBuilt/Aps:TestResult" />
> </xsl:template>
>
> <xsl:templates match="Aps:Drawing">
> <tr>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:Name"/></td>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:TopAssemblyName"/></td>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:PartNumber"/></td>
>
> <td><xsl:value-of select="Aps:DocumentId"/></td>
> <td><a><xsl:attribute
> name="href">/assist/model/apsVpmSheets/?id=<xsl:value-of
> select="ancestor::Aps:PartStructure/@ino:id"/>&type=Aps:AsDesigned/Aps:Drawing&name=<xsl:value-of
> select="Aps:Name"/>
> </xsl:attribute><xsl:value-of select="Aps:Name"/>
> </a>
> </td>
> </tr>
> </xsl:template>
>
> <xsl:templates match="Aps:Specification">
> <tr>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:Name"/></td>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:TopAssemblyName"/></td>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:PartNumber"/></td>
>
> <td><xsl:value-of select="Aps:DocumentId"/></td>
> <td><a><xsl:attribute
> name="href">/assist/model/apsVpmSheets/?id=<xsl:value-of
> select="ancestor::Aps:PartStructure/@ino:id"/>&type=Aps:AsDesigned/Aps:Specification&name=<xsl:value-of
> select="Aps:Name"/>
> </xsl:attribute><xsl:value-of select="Aps:Name"/>
> </a>
> </td>
> </tr>
> </xsl:template>
>
> <xsl:templates match="Aps:TestResult">
> <tr>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:Name"/></td>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:TopAssemblyName"/></td>
> <td><xsl:value-of
> select="ancestor::Aps:PartStructure/Aps:PartNumber"/></td>
>
> <td><xsl:value-of select="Aps:DocumentId"/></td>
> <td><a><xsl:attribute
> name="href">/assist/model/apsVpmSheets/?id=<xsl:value-of
> select="ancestor::Aps:PartStructure/@ino:id"/>&type=Aps:AsBuilt/Aps:TestResult&name=<xsl:value-of
> select="Aps:Name"/>
> </xsl:attribute><xsl:value-of select="Aps:Name"/>
> </a>
> </td>
> </tr>
> </xsl:template>
>
> ------------------------------------------------------------------------------
> This message and any attachment is confidential and may be privileged or otherwise protected from disclosure. If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone.
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list