Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the input structure you have chosen to show us, this stylesheet will do.</p> <p><strong>EDIT</strong>: updated stylesheet</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="root"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="payload"&gt; &lt;xsl:copy&gt; &lt;xsl:value-of select="."/&gt; &lt;xsl:value-of select="following-sibling::metadata/metadata-element[key='foo']/value"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="metadata[metadata-element/key='key']"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="metadata-element|key|value"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="metadata[metadata-element/key='foo']"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Yields the following output: <strong>EDIT</strong>: Updated output</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root&gt; &lt;payload&gt;012345678&lt;/payload&gt; &lt;metadata&gt; &lt;metadata-element&gt; &lt;key&gt;key&lt;/key&gt; &lt;value&gt;value&lt;/value&gt; &lt;/metadata-element&gt; &lt;/metadata&gt; &lt;/root&gt; </code></pre> <blockquote> <p>I know that something should be in tags but i dont really know what.</p> </blockquote> <p>Note that xsl:copy copies the node in context to the output tree. If your template matches <code>a</code> elements, this instruction copies <code>a</code> to the output tree. Any XLST code you write inside of <code>xsl:copy</code> will be placed inside of the copied element.</p> <p>Im am well aware that your input XML is in fact very different, but you did not enclose it. Therefore, my post simply answers what you asked for.</p>
    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.
 

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