Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help with simple XPATH

From: Myron Turner <mturner@--.---------.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent