Subject: Re: [xsl] Trouble writing .xsl From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Sun, 13 Jan 2002 18:50:56 +0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Trouble writing .xsl, Jason Rizer | Thread | Re: [xsl] Trouble writing .xsl, Jason Rizer |
RE: [xsl] Trouble writing .xsl, Jason Rizer | Date | Re: [xsl] Re: A question about the , Jeni Tennison |
Month |