Note that there are some explanatory texts on larger screens.

plurals
  1. POTransforming a sequence of tags using XSL
    text
    copied!<p>I'm kind of new to using <a href="http://en.wikipedia.org/wiki/Extensible_Stylesheet_Language" rel="nofollow noreferrer">XSL</a>. I'm trying to convert an XML file into another XML file with a different structure using XSL. The <strong>input</strong> section of the XML goes like this:</p> <pre><code>&lt;tag&gt; &lt;Keyword&gt;Event: Some Text&lt;/Keyword&gt; &lt;Keyword&gt;Group: Some Text&lt;/Keyword&gt; &lt;Keyword&gt;Other: Some Text&lt;/Keyword&gt; &lt;/tag&gt; </code></pre> <p>I would like the desired <strong>output</strong> to be:</p> <pre><code>&lt;tag&gt; &lt;event&gt; Some Text &lt;/event&gt; &lt;group&gt; Some Text &lt;/group&gt; &lt;other&gt; Some Text &lt;/other&gt; &lt;/tag&gt; </code></pre> <p>My <strong>current XSL</strong> file:</p> <pre><code>&lt;xsl:for-each select="tag"&gt; &lt;xsl:if test="starts-with(Keyword, 'Event: ')"&gt; &lt;event&gt; &lt;xsl:value-of select="substring-after(Keyword, 'Event: ')"/&gt; &lt;/event&gt; &lt;/xsl:if&gt; &lt;xsl:if test="starts-with(Keyword, 'Group: ')"&gt; &lt;group&gt; &lt;xsl:value-of select="substring-after(Keyword, 'Group: ')"/&gt; &lt;/group&gt; &lt;/xsl:if&gt; &lt;xsl:if test="starts-with(Keyword, 'Other: ')"&gt; &lt;other&gt; &lt;xsl:value-of select="substring-after(Keyword, 'Other: ')"/&gt; &lt;/other&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; </code></pre> <p>The <strong>current output</strong> only shows the event node and does not display the remaining nodes:</p> <pre><code>&lt;tag&gt; &lt;event&gt; Some Text &lt;/event&gt; &lt;/tag&gt; </code></pre> <p>I tried switching the 'group' section with the 'event' section in the XSL, however all the child nodes are not displayed probably due to the ordering of the keyword nodes in the input XML. So how can I read <strong>all</strong> the keyword nodes and convert them to the respective new nodes for display?</p>
 

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