views:

82

answers:

3
<AgoraServersConfig>
  <AgoraServers id="NYQ1">
    <AgoraName>prod</AgoraName>
    <TableName>someTable</TableName>
    <Rule_ID>1</Rule_ID>
    <Rule_ID>3</Rule_ID>
    <Rule_ID>5</Rule_ID>
  </AgoraServers>
  <AgoraServers id ="QA03">
    <AgoraName>dev</AgoraName>
    <TableName>someTable</TableName>
    <Rule_ID>1</Rule_ID>
    <Rule_ID>2</Rule_ID>
    <Rule_ID>5</Rule_ID>
  </AgoraServers>
</AgoraServersConfig>

Given the above schema, I would like to know how to frame an Xpath query that returns the children of the node whose id is "QA03", for example.

Many Thanks in advance

A: 

I'm not sure I fully understand your schema, but to return children of a node based on that node's id attribute would look something like

//*[@id='QA03']/*
Greg
A: 

The xpath would look like this:

/AgoraServersConfig/AgoraServers[@id='QA03']/*

If you wanted to do something a bit more dynamic, you could put the id into a variable, e.g.

<xsl:variable name="targetid">QA03</xsl:variable>
<xsl:for-each select="/AgoraServersConfig/AgoraServers[@id=$targetid]/*">
    <xsl:copy-of select="."/>
</xsl:for-each>
Olly Hodgson
thanks olly, i went with your 'static' xpath...worked well :)
Rishi Poptani
A: 

Use:

/*/*[@id='QA03']/node()

It is also possible to use the standard XPath function id().

However, for this to work, there must be a DTD for the XML document that defines id as an "ID-type attribute".

Example: id('QA03')/node()

Dimitre Novatchev
thanks dimitre... and yes, m using a standard DTD, so no problem with the id..
Rishi Poptani