I'm finally back to trying to figure this one out. I'm definitely sure
now that XUpdate isn't very helpful in terms of making this easy for
me, so I'm looking at a couple different ways of doing it.
Unfortantely, Zarella's solution, won't work for me becuase not just
the country, but the whole path, is a parameter.
I'm considering now, that it might actually be easier to just generate
an XSLT (using XSLT...) that does what I want, and then run it (I can
do this in AxKit..) in other words, code generation. Has anyone else
ever done this?
Simon
On Monday, February 3, 2003, at 10:55 AM, Zarella Rendon wrote:
Hi Simon,
You can work off the name element and use following-sibling to check
for the
existence of the address and add it if it's not there. This is not an
"XPath" solution, but it will work.
<xsl:param name="country">XLandia</xsl:param>
<xsl:template match="/resume/header/name">
<xsl:copy-of select="."/>
<xsl:if test="not(following-sibling::address)">
<address>
<country>
<xsl:value-of select="$country"/>
</country>
</address>
</xsl:if>
</xsl:template>
Hope this helps.
Zarella
--------------
Zarella Rendon
Principal Consultant
XML-Factor Consulting Svcs.
www.xml-factor.com
zarella(_at_)xml-factor(_dot_)com
-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of S
Woodside
Sent: Tuesday, January 28, 2003 12:41 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] yet another XPath question
Seems like I'm trying to do "hard" things with Xpath these days. I
wish
there were a dedicated XPath mailing list or FAQ ... or is it that I'm
the only one trying to use XPath in this way?
I'm passing an XPath back from an HTML form as a parameter to an XSLT
stylesheet. I'm also passing a value to insert into that location,
using, XUpdate (specifically XML::XUpdate::LibXML in perl). I'd like
to
then test the source document for the stylesheet, to see if that XPath
is valid. 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:
source XML docu:
<resume>
<header>
<name>
<first>Simon</first>
</name>
</header>
</resume>
params from HTML forms into XSLT:
XPath: /resume/header/address/country
Value: XLandia
result XML docu:
<resume>
<header>
<name>
<first>Simon</first>
</name>
<address>
<country>
XLandia
</country>
</address>
</header>
</resume>
How do I do that? There doesn't seem to be any convenient way to break
apart and analyse xpath steps in the spec, and I /don't/ want to start
messing around with string conversions...
simon
---
www.simonwoodside.com
<http://ThisURLEnablesEmailToGetThroughOverzealousSpamFilters.org>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list