[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Trouble writing .xsl
Subject: Re: [xsl] Trouble writing .xsl From: Jason Rizer <jasonriz@xxxxxxxxx> Date: Sun, 13 Jan 2002 15:42:34 -0800 (PST) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Trouble writing .xsl, Jeni Tennison | Thread | RE: [xsl] Trouble writing .xsl, Sullivan, Dan |
Re: [xsl] sorting to a variable, David Carlisle | Date | RE: [xsl] Trouble writing .xsl, Jason Rizer |
Month |
Keywords