Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This can be achieved with a very short and simple transformation -- no <code>&lt;xsl:for-each&gt;</code>, no <code>&lt;xsl:if&gt;</code>, <code>&lt;xsl:choose&gt;</code>, <code>&lt;xsl:when&gt;</code>,no <code>&lt;xsl:attribute&gt;</code> at all</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="Book[Web/text()]"&gt; &lt;p&gt; &lt;a href="{Web}"&gt; &lt;xsl:value-of select="Pub"/&gt; &lt;/a&gt; &lt;/p&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Book"&gt; &lt;p&gt; &lt;xsl:value-of select="Pub"/&gt; &lt;/p&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on the provided XML document</strong>:</p> <pre><code>&lt;Catalog&gt; &lt;Book&gt; &lt;AName&gt;Steven Holzner&lt;/AName&gt; &lt;BName&gt;Using XSLT&lt;/BName&gt; &lt;Pub&gt;ABC Publication &lt;/Pub&gt; &lt;Web&gt;http://www.ABCPub.com&lt;/Web&gt; &lt;/Book&gt; &lt;Book&gt; &lt;AName&gt;Steven Holzner&lt;/AName&gt; &lt;BName&gt;Using HTML&lt;/BName&gt; &lt;Pub&gt;XYZ Publication &lt;/Pub&gt; &lt;Web&gt;&lt;/Web&gt; &lt;/Book&gt; &lt;/Catalog&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;p&gt; &lt;a href="http://www.ABCPub.com"&gt;ABC Publication &lt;/a&gt; &lt;/p&gt; &lt;p&gt;XYZ Publication &lt;/p&gt; </code></pre> <p><strong>Explanation</strong>: Template pattern matching.</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