Note that there are some explanatory texts on larger screens.

plurals
  1. POChoose from XML node with multiple category elements
    primarykey
    data
    text
    <p>I have an XML document with a collection of news articles that have been assigned to multiple categories. I now need to group these documents by category. Below is a sample item record: </p> <pre><code>&lt;item&gt; &lt;link&gt;http://www.threelanews.com/articles/?id=50456&lt;/link&gt; &lt;category&gt;/General/&lt;/category&gt; &lt;category&gt;/Technology/&lt;/category&gt; &lt;category&gt;/Technology/Telecommunications/&lt;/category&gt; &lt;category&gt;/Technology/Information Technology/Internet/&lt;/category&gt; &lt;title&gt;Sony debuts handsets at CES&lt;/title&gt; &lt;description&gt;The Xperia S will be available globally from the first quarter of 2012.&amp;#xD;Sony Ericsson will showcase the first handsets from...&lt;/description&gt; &lt;pubDate&gt;Tue, 10 Jan 2012 12:11:01 +0200&lt;/pubDate&gt; &lt;/item&gt; </code></pre> <p>I am using an XSL stylesheet to transform the document. For each group, I will do a test to see what elements belong to that category and if there is a match in one of the category elements, the article should be added to the html eg:</p> <pre><code>&lt;xsl:when test="contains(category,'/General/')"&gt; &lt;div class="news-item" width="100%"&gt; &lt;div class="news-item-title" width="100%"&gt; &lt;a href="{$linkUrl}" target="_blank"&gt; &lt;xsl:value-of select="title"/&gt; &lt;/a&gt; &lt;/div&gt; &lt;xsl:if test="string-length($imageUrl) &amp;gt; 0"&gt; &lt;div class="news-item-image"&gt; &lt;img src="{$imageUrl}" /&gt; &lt;/div&gt; &lt;/xsl:if&gt; &lt;div class="news-item-description"&gt; &lt;xsl:value-of select="description"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="clear" /&gt; &lt;/xsl:when&gt; </code></pre> <p>Then the article should be added to the "General Group". Articles with multiple categories should appear in each group that they are relevant. The above statement will work for the "General" group but when I try to do the same for "Technology" or the other categories below it, this article is not returned. I have found it is only doing the match on the first element. Is there any way I couuld do the match on all the category elements?</p>
    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.
 

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