Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use templates to define behavior on specific elements</p> <pre><code>&lt;!-- after standard identity template --&gt; &lt;xsl:template match="description"&gt; &lt;xsl:element name="newprice"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="p"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; </code></pre> <p>The first template says to swap <code>description</code> with <code>newprice</code>. The second one says to ignore the <code>p</code> element.</p> <p>If you're unfamiliar with the identity template, <a href="http://www.xmlplease.com/xsltidentity" rel="nofollow noreferrer">take a look here</a> for a few examples.</p> <p><strong>EDIT</strong>: Given the new example, we can see that you want to only extract the description element and its contents. Notice that the template action starts with the <code>match="/"</code> template. We can use this control where our stylesheet starts and thus skip much of the riffraff we want to filter out.</p> <p>change the <code>&lt;xsl:template match="/"&gt;</code> to something more like:</p> <pre><code> &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="//description"/&gt; &lt;!-- use a more specific XPath if you can --&gt; &lt;/xsl:template&gt; </code></pre> <p>So altogether our solution looks like this:</p> <pre><code>&lt;xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="xs"&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="//description" /&gt; &lt;/xsl:template&gt; &lt;!-- this is the identity template --&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="description"&gt; &lt;xsl:element name="newprice"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="p"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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