Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPATH query - one statement works and one doesn't

Status
Not open for further replies.

supermatchgame

Programmer
May 16, 2007
50
GB
I have an xml fragment from the start of a file:

Code:
<DataSourceMessage xmlns="[URL unfurl="true"]http://www.govtalk.gov.uk/Education[/URL]
/ISIndexDataSourceMessage" xmlns:apd="[URL unfurl="true"]http://www.govtalk.gov.uk/people[/URL]
/AddressAndPersonalDetails" xmlns:bs7666="[URL unfurl="true"]http://www.govtalk.gov.uk/people[/URL]
/bs7666" xmlns:cdt="[URL unfurl="true"]http://www.govtalk.gov.uk/people/ContactDetails"[/URL] 
xmlns:ind="[URL unfurl="true"]http://www.govtalk.gov.uk/Education/ISIndexCommon"[/URL] 
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] 
xsi:schemaLocation="[URL unfurl="true"]http://www.govtalk.gov.uk/Education[/URL]
/ISIndexDataSourceMessageISIndexDataSourceMessage-v1-1.xsd">
- <DataSourceHeader>
  <ind:SourceSystemDomain /> 
  <ind:SourceSystemCode /> 
  <ind:SentTimestamp>2008-08-18T12:58:39</ind:SentTimestamp> 
  <ind:RecordCount>MADEUP</ind:RecordCount> 
  <ind:LoadAction>MADEUP</ind:LoadAction> 
  <ind:DataSourceBatchId /> 
  </DataSourceHeader>
- <DataSourceRecords>
- <ind:DataSourceRecord CorrelationId="4">
- <ind:ChildNames>
- <ind:ChildName>
  <ind:FamilyName>MADEUPDATA</ind:FamilyName>


Please can someone tell me why the following XPATH statement will return the value of the <ind:FamilyName> element:

Code:
<xsl:value-of select="//ind:FamilyName"></xsl:value-of>

but this statement won't:

Code:
<xsl:value-of select="/DataSourceMessage/DataSourceRecords
/ind:DataSourceRecord/ind:ChildNames/ind:ChildName/ind:FamilyName"/>

I'm using the XSL debug tool in Visual Studio 2005 but XPATh is XPATH regardless of platform, right?
 
In your xsl document, you have to declare the namespace uri corresponding to ...ISIndexDataSourceMessage, say, usually at the root xsl:stylesheet, like this.
[tt][ignore]
xmlns:x="[/ignore][/tt]
Your xpath (2nd version) would look like this and it will be fine.
[tt]
<xsl:value-of select="/[red]x:[/red]DataSourceMessage/[red]x:
[/red]DataSourceRecords/ind:DataSourceRecord/ind:ChildNames/ind:ChildName
/ind:FamilyName"/>
[/tt]
 
Thankyou so much for your help - I always, always get the namespace information wrong!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top