fkinfubar Posted November 13, 2007 Share Posted November 13, 2007 Hi everyone,I have a problem with a piece of xslt I am attempting to write. I have a XML file like this: <messages idnext="3"> <message id="1"> <subject>subject</subject> <body>body</body> <replies> <message id="2"> <subject>RE: subject</subject> <body>body</body> <replies /> </message> </replies> </message></messages> And I want to select just the top level messages first, display them and then have a list of the follow ups below.The problem is I don't seeem to be able to come up with a way of differentiating between top level and reply messages.I have tried to use template matches on the message nodes but this just gives me the full list no matter what match string I use.I know I am a total newbie, but I only started today!thanks for any help. Link to comment Share on other sites More sharing options...
Reg Edit Posted November 13, 2007 Share Posted November 13, 2007 [...] The problem is I don't seeem to be able to come up with a way of differentiating between top level and reply messages.I have tried to use template matches on the message nodes but this just gives me the full list no matter what match string I use [...]The xpath for the top-level messages is:/messages/message So an example of a template to display their ids would be: <xsl:template match="/"> <xsl:for-each select="/messages/message" > <xsl:value-of select="@id"/> </xsl:for-each></xsl:template> If you're getting the lower-level ones too, perhaps you have //message instead of /message?There's a web page here where you can try out xpath queries and see the results. Link to comment Share on other sites More sharing options...
fkinfubar Posted November 13, 2007 Author Share Posted November 13, 2007 The xpath for the top-level messages is:/messages/message So an example of a template to display their ids would be: <xsl:template match="/"> <xsl:for-each select="/messages/message" > <xsl:value-of select="@id"/> </xsl:for-each></xsl:template> If you're getting the lower-level ones too, perhaps you have //message instead of /message?There's a web page here where you can try out xpath queries and see the results. Thanks a lot for your help! It was just a case of too many foward slashes spoil the broth Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.