|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Omit Data While Using Copy
> <?xml version='1.0' encoding='UTF-8' ?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="kapitel">
>
> <h2><xsl:value-of select="titel"/></h2>
>
> <xsl:for-each select="hanvisning">
>
> <br><a><xsl:attribute name="href"><xsl:value-of
>
> select="substring-before(substring-after(@from,'('),')')"/>.xm
> l</xsl:attribute><xsl:value-of
>
> select="node()"/></a></br>
>
> </xsl:for-each>
>
> <br></br><br></br><a><xsl:attribute
> name="href">2.xml</xsl:attribute>Return to Home Page</a>
>
> </xsl:template>
> </xsl:stylesheet>
>
>
> I suspect this wasn't the best way to accomplish this, but it
> does work.
> Since I am just starting to use xsl, I'd prefer to learn to
> do things the
> correct way, rather than modifying code to make it do what I
> need it to.
>
> Any suggestions to improve this code would be greatly appreciated.
Two suggestions:
1. It's usually easier to use attribute value templates. Replace:
<a><xsl:attribute name="href">2.xml</xsl:attribute>Return to Home Page</a>
with
<a href="2.xml">Return to Home Page</a>
and
<a><xsl:attribute name="href">
<xsl:value-of
select="substring-before(substring-after(@from,'('),')')"/>.xml</xsl:attribu
te>
<xsl:value-of select="node()"/></a>
with
<a href="{substring-before(substring-after(@from,'('),')')}.xml">
<xsl:value-of select="node()"/>
</a>
2. Use apply-templates and template rules rather than xsl:for-each and
xsl:value-of.
Beginners tend to reach for for-each and value-of because they seem simpler
and more familiar. But using "push" processing with apply-templates and
template rules isn't difficult to master and leads to much more easily
maintainable code.
Michael Kay
>
> Thanks again to all those who helped.
>
> Trevor
> P.S.
> Hopefully, it won't be long before I am able to offer
> some help to
> others! :)
>
> _________________________________________________________________
> MSNR Calendar keeps you organized and takes the effort out of
> scheduling
> get-togethers.
> http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&
> DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
> Start enjoying all the benefits of MSNR Premium right now
> and get the
> first two months FREE*.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








