Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT recursion and 2 parameters
    text
    copied!<p>I'm having trouble getting XML data to format properly in HTML via XSLT. Here is how data is received:</p> <pre><code> This is some text. &lt;p&gt; This is more text. &lt;p&gt; This is even more text. &lt;p&gt; &lt;a href=www.google.com&gt;Google's website&lt;/a&gt; &lt;p&gt; Return to my website. </code></pre> <p>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:</p> <pre><code>&lt;xsl:template name="replace_p"&gt; &lt;xsl:param name="text"/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="contains($text, '&amp;lt;P&amp;gt;')"&gt; &lt;xsl:value-of select="substring-before($text, '&amp;lt;P&amp;gt;')"/&gt; &lt;br/&gt;&lt;br/&gt; &lt;xsl:call-template name="replace_p"&gt; &lt;xsl:with-param name="text" select="substring-after($text, '&amp;lt;P&amp;gt;')"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="$text"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; </code></pre> <p>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):</p> <pre><code> &lt;xsl:template name="replace_p"&gt; &lt;xsl:param name="text"/&gt; &lt;xsl:if test="contains($text, '&amp;lt;P&amp;gt;')"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="substring-before($text, '&amp;lt;P&amp;gt;') and substring-before($text, '&amp;lt;a href=')"&gt; &lt;xsl:value-of select="substring-before(substring-after($text, '&amp;lt;a href='), '&amp;gt;')"/&gt; &lt;br/&gt;&lt;br/&gt; &lt;xsl:call-template name="replace_p"&gt; &lt;xsl:with-param name="text" select="substring-after($text, '&amp;lt;P&amp;gt;')"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:when test="substring-before($text, '&amp;lt;P&amp;gt;')"&gt; &lt;xsl:value-of select="substring-before($text, '&amp;lt;P&amp;gt;')"/&gt; &lt;br/&gt;&lt;br/&gt; &lt;xsl:call-template name="replace_p"&gt; &lt;xsl:with-param name="text" select="substring-after($text, '&amp;lt;P&amp;gt;')"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="$text"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; </code></pre> <p>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?</p> <p>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. :)</p> <p>Please let me know if any other information is needed. </p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload