Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT for-each of a node
    primarykey
    data
    text
    <p>I have the following XML structure residing within a <strong>namespace</strong>:</p> <pre><code>&lt;School&gt; &lt;SchoolInfo&gt; &lt;SchoolName&gt;The Big School&lt;/SchoolName&gt; &lt;Opened&gt;2008&lt;/Opened&gt; &lt;SchoolID&gt;SCH1122&lt;/SchoolID&gt; &lt;Geograpics&gt; &lt;Location&gt;London&lt;/Location&gt; &lt;PostCode&gt;ZZ11 1ZZ&lt;/PostCode&gt; &lt;/Geographics&gt; &lt;/SchoolInfo&gt; &lt;Pupil&gt; &lt;Name&gt;Tom&lt;/Name&gt; &lt;LastName&gt;Jones&lt;/LastName&gt; &lt;Class&gt;12B&lt;/Class&gt; &lt;Age&gt;16&lt;/Age&gt; &lt;/Pupil&gt; &lt;Pupil&gt; &lt;Name&gt;Steve&lt;/Name&gt; &lt;LastName&gt;Jobs&lt;/LastName&gt; &lt;Class&gt;09A&lt;/Class&gt; &lt;Age&gt;17&lt;/Age&gt; &lt;/Pupil&gt; &lt;Pupil&gt; &lt;Name&gt;Joe&lt;/Name&gt; &lt;LastName&gt;Blogs&lt;/LastName&gt; &lt;Class&gt;13A&lt;/Class&gt; &lt;Age&gt;15&lt;/Age&gt; &lt;/Pupil&gt; &lt;/School&gt; </code></pre> <p>Using XSLTl I wish to create a PSV which looks like the following structure: (SchoolID|Location|Name|Class|Age)</p> <pre><code>SCH1122|London|Tom|12B|16 SCH1122|London|Steve|09A|17 SCH1122|London|Joe|13A|15 </code></pre> <p>Is this possible using XSLT and how would I go about this?</p> <p>Code so far:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="NamespaceHere" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:cs="urn:cs" exclude-result-prefixes="cs x msxsl" &gt; &lt;xsl:output method="text" omit-xml-declaration="yes" indent="no"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="x:SchoolID"&gt; &lt;xsl:value-of select="text()"/&gt; &lt;xsl:text&gt;|&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="x:PostCode"&gt; &lt;xsl:value-of select="text()"/&gt; &lt;xsl:text&gt;|&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="x:Name"&gt; &lt;xsl:value-of select="text()"/&gt; &lt;xsl:text&gt;|&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="x:Class"&gt; &lt;xsl:value-of select="text()"/&gt; &lt;xsl:text&gt;|&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="x:Age"&gt; &lt;xsl:value-of select="text()"/&gt; &lt;xsl:text&gt;|&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;xsl:template match="text()"&gt; &lt;xsl:apply-templates select="x:Message"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="x:School"&gt; &lt;xsl:apply-templates select="x:SchoolInfo/x:SchoolID"/&gt; &lt;xsl:apply-templates select="x:SchoolInfo/x:Geographics/x:PostCode"/&gt; &lt;xsl:apply-templates select="x:Pupil/x:Name"/&gt; &lt;xsl:apply-templates select="x:Pupil/x:Class"/&gt; &lt;xsl:apply-templates select="x:Pupil/x:Age"/&gt; &lt;xsl:text&gt;&amp;#0010;&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>This works when I have only one pupil however when I get multiple pupils the output becomes like the following:</p> <blockquote> <p>SCH1122|London|London|Tom|Steve|12B|09A|16|17</p> </blockquote>
    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. 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