[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Omit Data While Using Copy

Subject: RE: Omit Data While Using Copy
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 12 Aug 2004 17:37:24 +0100
xsl omit
> <?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*.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.