help with XPath expression
-
Here is my document:
<data> <meetings> <meeting id="900" title="Meeting Title" date="1/1/2005" location="Main Office"> <attendee personID="100" /> <attendee personID="101" /> </meeting> </meetings> <people> <person id="100" firstname="John" lastname="Doe" /> <person id="101" firstname="Jane" lastname="Smith" /> <person id="102" firstname="Jack" lastname="Williams" /> </people> </data>
I want to be able to display the meeting info, then display a table of meeting attendees. When displaying attendees, I want to match their related person info in a different node in the document. e.g. the desired output for the single meeting above would be: Meeting Title, Main Office, 1/1/2005 John Doe Jane Smith Here is how I'm approaching it:<xsl:template match="/data/meetings/meeting"> <xsl:for-each select="attendee"> <p> <xsl:value-of select="/data/people/person[@id=@personID]/@firstname" /> <xsl:value-of select="/data/people/person[@id=@personID]/@lastname" /> </p> </xsl:for-each> </xsl:template>
The stylesheet loads fine, but there is no output for each person. If I hard-code the @personID value in the query I'm using to get to the specific person, then it works fine. Where am I going wrong? Michael Hodnick www.kindohm.com -
Here is my document:
<data> <meetings> <meeting id="900" title="Meeting Title" date="1/1/2005" location="Main Office"> <attendee personID="100" /> <attendee personID="101" /> </meeting> </meetings> <people> <person id="100" firstname="John" lastname="Doe" /> <person id="101" firstname="Jane" lastname="Smith" /> <person id="102" firstname="Jack" lastname="Williams" /> </people> </data>
I want to be able to display the meeting info, then display a table of meeting attendees. When displaying attendees, I want to match their related person info in a different node in the document. e.g. the desired output for the single meeting above would be: Meeting Title, Main Office, 1/1/2005 John Doe Jane Smith Here is how I'm approaching it:<xsl:template match="/data/meetings/meeting"> <xsl:for-each select="attendee"> <p> <xsl:value-of select="/data/people/person[@id=@personID]/@firstname" /> <xsl:value-of select="/data/people/person[@id=@personID]/@lastname" /> </p> </xsl:for-each> </xsl:template>
The stylesheet loads fine, but there is no output for each person. If I hard-code the @personID value in the query I'm using to get to the specific person, then it works fine. Where am I going wrong? Michael Hodnick www.kindohm.comHi, this tries to select person whose id is same as personID. (it would work with data like this:
<person id="100" personID="100" firstname="John" lastname="Doe" />
) You need to tell parser, that attribute personID is not atribute of person tag, but attribute of attendee tag. I'm not sure if I'm correct, but try something like this: <xsl:value-of select="/data/people/person[@id=./@personID]/@firstname" /> Hope this helps:)Tomáš Petříček (Microsoft C# MVP)
www.eeeksoft.net | Asp.Net Graphical controls