• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xslt question

 
Trina Thach
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a multiple nested elements case (below), how can I write a condition in xslt to display all <body> tag contents if they belong to id=1 record? Please Help.
<topics>
<topic>
<id>1</id>
<msg>
<body>ABC</body>
<msg>
<body>efg</body>
<msg>
<body>hij</body>
</msg>
</msg>
</msg>
</topic>
</topics>
 
Dhananjay Goswami
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Trina,
You could try something like:
<xsl:variable name="reqList" select="/topics/topic[id=1]"/>
<!-- now, you have a list of the topic elements, all of which have id = 1-->
<xsl:template name="getBodyContent">
<xsl:for-each select="$reqList">
<xsl:text>Msg no: </xsl:text>
<xsl:number/>
<xsl:for-each select=".//body">

<xsl:value-of select="text()"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="getBodyContent"/>
</xsl:template>
Hope this helps
Dhananjay
 
Trina Thach
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dhananjay, It works perfectly the way I want it to be. Thank you so much for your help.
[ April 20, 2003: Message edited by: Trina Thach ]
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is way too complicated!
See this one:



You will get exact the same result. If you want to keep the space between words, just take the translate function away.

Thanks!
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I knew it was an old question.

I am just trying to find some exercises to pick-up my XSLT again, since not doing it for about 2.5 years.

I am also trying to update my XML FAQ's.
http://bobcat.webappcabaret.net/javachina/faq/xml_01.htm

Use it, or Lose it!
I try to hit two birds with one stone!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic