XSLT recursion and 2 parameters

CarrieM

New Member
I'm having trouble getting XML data to format properly in HTML via XSLT. Here is how data is received:\[code\] This is some text. <p> This is more text. <p> This is even more text. <p> <a href=http://stackoverflow.com/questions/10840524/www.google.com>Google's website</a> <p> Return to my website.\[/code\]So I have recursion (I think that is what's used in this case) setup. It will create a new paragraph for each p tag, and remove the p tag on our website. Here's the code:\[code\]<xsl:template name="replace_p"> <xsl:param name="text"/> <xsl:choose> <xsl:when test="contains($text, '<P>')"> <xsl:value-of select="substring-before($text, '<P>')"/> <br/><br/> <xsl:call-template name="replace_p"> <xsl:with-param name="text" select="substring-after($text, '<P>')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose>\[/code\]This works great...except when we have links. I want users to be able to click on the link rather than see the a href tag and code. Only problem is... how do I do this when the replace p template running. My attempt (I feel like I have the right idea, although probably not close):\[code\] <xsl:template name="replace_p"> <xsl:param name="text"/> <xsl:if test="contains($text, '<P>')"> <xsl:choose> <xsl:when test="substring-before($text, '<P>') and substring-before($text, '<a href='http://stackoverflow.com/questions/10840524/)"> <xsl:value-of select="substring-before(substring-after($text, '<a href='http://stackoverflow.com/questions/10840524/),'>')"/> <br/><br/> <xsl:call-template name="replace_p"> <xsl:with-param name="text" select="substring-after($text, '<P>')"/> </xsl:call-template> </xsl:when> <xsl:when test="substring-before($text, '<P>')"> <xsl:value-of select="substring-before($text, '<P>')"/> <br/><br/> <xsl:call-template name="replace_p"> <xsl:with-param name="text" select="substring-after($text, '<P>')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:if></xsl:template>\[/code\]I put the test of p tag and a href tag test first, because I want it to check both before going to the next when statement. BUT... I don't know if that's how it necessarily works. Will it check the first p tag and a href tag before going to the next when statement?I also know I need to create an a tag and an href attribute, but i'd like to work on getting the right data to show up first. :)Please let me know if any other information is needed. Thanks!
 
Back
Top