Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you sure you want to unwrap the individual <code>Customers</code>?</p> <p>It looks like your stylesheet wasn't working because of these two templates:</p> <pre><code>&lt;xsl:template match="Customers/City"&gt; &lt;xsl:element name="Address"&gt; &lt;xsl:element name="City"&gt; &lt;xsl:value-of select="." /&gt; &lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Customers/Country"&gt; &lt;xsl:element name="Address"&gt; &lt;xsl:element name="Country"&gt; &lt;xsl:value-of select="." /&gt; &lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; </code></pre> <p>These are giving you two different <code>Address</code> elements.</p> <p>You <em>could</em> do something like:</p> <pre><code>&lt;xsl:template match="Customers/City"&gt; &lt;Address&gt; &lt;City&gt; &lt;xsl:value-of select="." /&gt; &lt;/City&gt; &lt;Country&gt; &lt;xsl:value-of select="following-sibling::Country"/&gt; &lt;/Country&gt; &lt;/Address&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Customers/Country"/&gt; </code></pre> <p>Here's a similar XSLT 1.0 stylesheet that gives the wanted result and is a little cleaner in my opinion:</p> <p><strong>XSLT 1.0</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&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="MyCustomer"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*"/&gt; &lt;Customers&gt; &lt;xsl:apply-templates select="node()"/&gt; &lt;/Customers&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Customers"&gt; &lt;xsl:apply-templates select="node()[not(self::City) and not(self::Country)]"/&gt; &lt;Address&gt; &lt;xsl:apply-templates select="City|Country"/&gt; &lt;/Address&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>XML Output</strong></p> <pre><code>&lt;MyCustomer&gt; &lt;Customers&gt; &lt;CutomerCode&gt;C001&lt;/CutomerCode&gt; &lt;CustomerName&gt;Shahbaz&lt;/CustomerName&gt; &lt;Address&gt; &lt;City&gt;Karachi&lt;/City&gt; &lt;Country&gt;Pakistan&lt;/Country&gt; &lt;/Address&gt; &lt;CutomerCode&gt;C002&lt;/CutomerCode&gt; &lt;CustomerName&gt;Imran&lt;/CustomerName&gt; &lt;Address&gt; &lt;City&gt;Lahore&lt;/City&gt; &lt;Country&gt;Pakistan&lt;/Country&gt; &lt;/Address&gt; &lt;/Customers&gt; &lt;/MyCustomer&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.
 

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