Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that you are looking for something like this:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns:exr="http://www.ecb.int/vocabulary/2002-08-01/eurofxref" exclude-result-prefixes="gesmes exr" &gt; &lt;xsl:output method="xml" indent="yes" encoding="utf-8" /&gt; &lt;xsl:template match="gesmes:Envelope"&gt; &lt;xdoc&gt; &lt;ccurency&gt; &lt;xsl:apply-templates select="exr:Cube/exr:Cube/exr:Cube" /&gt; &lt;/ccurency&gt; &lt;/xdoc&gt; &lt;/xsl:template&gt; &lt;xsl:template match="exr:Cube[@currency and @rate]"&gt; &lt;row&gt; &lt;Date&gt; &lt;xsl:value-of select="../@time" /&gt; &lt;/Date&gt; &lt;Currency&gt; &lt;xsl:value-of select="@currency" /&gt; &lt;/Currency&gt; &lt;Rate&gt; &lt;xsl:value-of select="@rate" /&gt; &lt;/Rate&gt; &lt;/row&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>When applied to your input XML, it produces:</p> <pre><code>&lt;xdoc&gt; &lt;ccurency&gt; &lt;row&gt; &lt;Date&gt;2009-07-16&lt;/Date&gt; &lt;Currency&gt;PHP&lt;/Currency&gt; &lt;Rate&gt;67.739&lt;/Rate&gt; &lt;/row&gt; &lt;row&gt; &lt;Date&gt;2009-07-16&lt;/Date&gt; &lt;Currency&gt;SGD&lt;/Currency&gt; &lt;Rate&gt;2.0501&lt;/Rate&gt; &lt;/row&gt; &lt;row&gt; &lt;Date&gt;2009-07-16&lt;/Date&gt; &lt;Currency&gt;THB&lt;/Currency&gt; &lt;Rate&gt;48.13&lt;/Rate&gt; &lt;/row&gt; &lt;row&gt; &lt;Date&gt;2009-07-16&lt;/Date&gt; &lt;Currency&gt;ZAR&lt;/Currency&gt; &lt;Rate&gt;11.4575&lt;/Rate&gt; &lt;/row&gt; &lt;/ccurency&gt; &lt;/xdoc&gt; </code></pre> <p>Notes:</p> <ul> <li>Don't use <code>&lt;xsl:for-each&gt;</code> whenever possible. It looks more familiar and less frightening than <code>&lt;xsl:apply-templates&gt;</code>, but it is not the best option most of the time.</li> <li>You don't need to build elements with <code>&lt;xsl:element&gt;</code>, you can write them directly.</li> <li>You don't need to store a variable with that <code>@time</code> value you are interested in. You can always refer to the parent node and pull it from there directly (<code>../@time</code>)</li> <li>I used <code>exclude-result-prefixes</code> to make namespaces disappear from the output entirely, you seem to want to get rid of them</li> </ul>
    singulars
    1. This table or related slice is empty.
    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