This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: for-each: is there a better way to do this?



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"/>&amp;type=Aps:AsDesigned/Aps:Drawing&amp;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"/>&amp;type=Aps:AsDesigned/Aps:Specification&amp;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"/>&amp;type=Aps:AsBuilt/Aps:TestResult&amp;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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]