Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Help with simple XPATH [Thread Next] Re: Help with simple XPATHTo: NULL Date: 1/5/2007 5:28:00 AM
Monty wrote:
> Despite reading posts in Google, I don't understand XPATH. Can someone
> help me write an XPATH. From Google I think my problem is that the
> default namespace does not have a prefix. I can't change this as I have
> received this XML and I didn't create it. All I want to is retrieve the
> PROJECTNAME from the following XML. I am typing this XML and XPATH into
> this site
>
> http://www.activsoftware.com/xml/xpath/
>
> The XPATH that does not work is /PROJECTS/PROJECTNAME.
>
> Thank you
> Monty
>
> <PROJECTS xmlns="http://www.companyname.com/project"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <PROJECTNAME>
> Project A
> </PROJECTNAME>
> <PROJECTBUDGET>
> 27000
> </PROJECTBUDGET>
> </PROJECTS>
>
You have to supply namespace prefixes in xsl/xpath for default
namespaces in xml. It took a bit of fussing, but here's a solution:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml" >
<xsl:template xmlns:pn="http://www.companyname.com/project" match="/">
<xsl:apply-templates select="pn:PROJECTS/pn:PROJECTNAME" />
<xsl:apply-templates select="pn:PROJECTS/pn:PROJECTBUDGET" />
</xsl:template>
<xsl:template xmlns:pn="http://www.companyname.com/project"
match="pn:PROJECTNAME">
Project Name: <xsl:value-of select = "." /><br />
</xsl:template>
<xsl:template xmlns:pn="http://www.companyname.com/project"
match="pn:PROJECTBUDGET">
Budget: <xsl:value-of select = "." />
</xsl:template>
</xsl:stylesheet>
--
_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
