Note that there are some explanatory texts on larger screens.

plurals
  1. POPreserving whitespaces from the XSL stylesheet
    primarykey
    data
    text
    <p>I'm trying to convert this XML :- </p> <pre><code>&lt;list&gt; &lt;unit&gt; &lt;data1&gt;a&lt;/data1&gt; &lt;data2&gt;b&lt;/data2&gt; &lt;data3&gt;c&lt;/data3&gt; &lt;/unit&gt; &lt;/list&gt; </code></pre> <p>to this :- </p> <pre><code>&lt;list&gt; &lt;unit&gt; &lt;category1&gt; &lt;data1&gt;a&lt;/data1&gt; &lt;data2&gt;b&lt;/data2&gt; &lt;/category1&gt; &lt;category2&gt; &lt;data3&gt;c&lt;/data3&gt; &lt;/category2&gt; &lt;/unit&gt; &lt;/list&gt; </code></pre> <p>using XSL. I'm using the following XSL:- </p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="some_namespace"&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="//s:unit" xml:space="preserve"&gt; &lt;xsl:copy&gt; &lt;category1&gt; &lt;xsl:apply-templates select="./s:data1"/&gt; &lt;xsl:apply-templates select="./s:data2"/&gt; &lt;/category1&gt; &lt;category2&gt; &lt;xsl:apply-templates select="./s:data3"/&gt; &lt;/category2&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Now, this preserves the indentation within but completely messes it up w.r.t. list. This is what I get :- </p> <pre><code> &lt;list&gt; &lt;unit&gt; &lt;category1&gt; &lt;data1&gt;a&lt;/data1&gt; &lt;data2&gt;b&lt;/data2&gt; &lt;/category1&gt; &lt;category2&gt; &lt;data3&gt;c&lt;/data3&gt; &lt;/category2&gt; &lt;/unit&gt; &lt;/list&gt; </code></pre> <p>What am I missing here? </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.
 

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