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

Re: Trouble writing .xsl

Subject: Re: Trouble writing .xsl
From: Jason Rizer <jasonriz@xxxxxxxxx>
Date: Sun, 13 Jan 2002 15:42:34 -0800 (PST)
elements named after jason
Jani,

Thanks a million.  I've now got everything working
perfectly ( I think :) )

-Jason
--- Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> wrote:
> Hi Jason,
> 
> > Thanks, this solved my problem (as I stated it)
> perfectly. You're 8
> > lines of XPATH did what my 50 couldn't :) I guess
> there is a bit of
> > a learning curve. Still, I have one additional
> problem. I realized
> > that I didn't quite state my problem fully. It's
> not suffiecent that
> > I replace elements named ABC:jason.Smith with
> elements named
> > ABC:Smith, I've also got to repace any elements
> whose names begin
> > with ABC:jason.Smith the elements whose names
> begin with ABC:Smith
> > while leaving the rest of the element name
> unchanged.
> 
> This is a little trickier, but ends up being the
> same number of lines
> ;)
> 
> You need to replace the template that currently
> matches elements
> named ABC:jason.Smith with one that matches any
> element in the ABC
> namespace whose local name (the bit after the ABC:
> prefix) starts with
> 'jason.Smith'.
> 
> You can match elements in the ABC namespace with:
> 
>   ABC:*
> 
> Then you can use a predicate to test them further:
> 
>   ABC:*[...]
> 
> You can get the local name with the local-name()
> function; and you can
> test whether a string begins with another string
> with the
> starts-with() function. So the pattern is:
> 
>   ABC:*[starts-with(local-name(), 'jason.Smith')]
> 
> Within the template, your first task is to work out
> the name of the
> element that you want to create. This is the part of
> the local name of
> the element after the 'jason.'. You can use the
> substring-after()
> function to get this (or you could use substring(),
> but I think
> substring-after() is clearer):
> 
>   substring-after(local-name(), 'jason.')
> 
> Your second task is to create an element of that
> name. You can do this
> with an xsl:element element; the name attribute of
> xsl:element is an
> attribute value template, which means that you can
> use calculated
> values if you wrap them in {}s:
> 
>   <xsl:element name="{substring-after(local-name(),
> 'jason.')}">
>     ...
>   </xsl:element>
> 
> The rest of the template is the same - applying
> templates to
> attributes and children in order to copy them via
> the identity
> template. So the substitute template as a whole is:
> 
> <xsl:template match="ABC:*[starts-with(local-name(),
> 'jason.Smith')]">
>   <xsl:element name="{substring-after(local-name(),
> 'jason.')}">
>     <xsl:apply-templates select="@*|node()" />
>   </xsl:element>
> </xsl:template>
> 
> I hope that helps,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

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


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.