Re: [xsl] yet another XPath question

Subject: Re: [xsl] yet another XPath question
From: S Woodside <sbwoodside@xxxxxxxxx>
Date: Mon, 3 Feb 2003 00:09:06 -0500
Américo, thank you so much for this. I'm still working on understanding it; I'm sure it will be a great help. I never imagined using substring so much in XSLT!


On Thursday, January 30, 2003, at 11:00 AM, Américo Albuquerque wrote:

Hi Simon.

I code this little template to do what you want, it doesn't use xpath
but an indentity template with a recursive template.
Hope this helps you.

 <xsl:param name="path" select="'/resume/header/address/country'"/>
 <xsl:param name="value" select="'XLandia'"/>

<xsl:template match="*">
<xsl:variable name="localpath">
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="name()"/>
<xsl:variable name="child"
select="substring-before(substring($path,string- length($localpath)+2),'/
<xsl:copy-of select="@*"/>
if $child isn't realy a child $localpath isn't the start of $path then
This test could be improved. It make sure that we are on the right
path and there is no child with that name.
If the last name ('country' in your example) already exists it doesn't
replace it, just adds another one with the same name and with the new
<xsl:if test="not(*[name()=$child]) and
<xsl:call-template name="create">
<xsl:with-param name="path"

 <xsl:template name="create">
  <xsl:param name="path"/>
  <xsl:variable name="step"
  <xsl:variable name="next" select="substring-after($path,'/')"/>
   <xsl:when test="not($step) and $next">
   <xsl:call-template name="create">
    <xsl:with-param name="path" select="$next"/>
   <xsl:when test="$step and not($next)">
   <xsl:element name="{$step}">
    <xsl:value-of select="$value"/>
   <xsl:when test="$step and $next">
   <xsl:element name="{$step}">
    <xsl:call-template name="create">
     <xsl:with-param name="path" select="$next"/>

-----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of S Woodside Sent: quinta-feira, 30 de Janeiro de 2003 2:12 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] yet another XPath question

So I guess there's no easy way out, eh? I'm sure I can code something up to do this...


On Tuesday, January 28, 2003, at 01:40 PM, S Woodside wrote:

OK, that's easy, I just test="/Big/Long/XPath" but wait, if it's /not/
present then I want to create sufficient nodes to insert the new
element in that place. That means I want to test each location step in

the XPath, one by one, from root to leaf, to see if it's there. If it
isn't, I then create a new node for that location step, and then
descend the rest of the XPath, creating nodes until I'm done and then
I insert the value. Here's an example of what I want to have happen:

XSL-List info and archive:

XSL-List info and archive:

     anti-spam: do not post this address publicly -- 99% Devil, 1% Angel

XSL-List info and archive:

Current Thread