Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This transformation:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:param name="pDriverPos"/&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/*"&gt; &lt;Vehicles&gt; &lt;xsl:apply-templates/&gt; &lt;/Vehicles&gt; &lt;/xsl:template&gt; &lt;xsl:template match="driver"&gt; &lt;xsl:apply-templates&gt; &lt;xsl:with-param name="pDriverPos" select="position()"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="vehicles"&gt; &lt;xsl:param name="pDriverPos"/&gt; &lt;xsl:apply-templates&gt; &lt;xsl:with-param name="pDriverPos" select="$pDriverPos"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="vehicle"&gt; &lt;xsl:param name="pDriverPos"/&gt; &lt;vehicle&gt; &lt;xsl:apply-templates/&gt; &lt;primarydriver&gt;&lt;xsl:value-of select="$pDriverPos"/&gt;&lt;/primarydriver&gt; &lt;/vehicle&gt; &lt;/xsl:template&gt; &lt;xsl:template match="first_name|last_name|records"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;drivers&gt; &lt;driver&gt; &lt;first_name&gt;Doug&lt;/first_name&gt; &lt;last_name&gt;Harry&lt;/last_name&gt; &lt;vehicles&gt; &lt;vehicle&gt; &lt;vin&gt;4T1BB46K08&lt;/vin&gt; &lt;year&gt;2008&lt;/year&gt; &lt;/vehicle&gt; &lt;/vehicles&gt; &lt;records/&gt; &lt;/driver&gt; &lt;driver&gt; &lt;first_name&gt;Sherry&lt;/first_name&gt; &lt;last_name&gt;Bloom&lt;/last_name&gt; &lt;vehicles&gt; &lt;vehicle&gt; &lt;vin&gt;5TDZA23C06&lt;/vin&gt; &lt;year&gt;2006&lt;/year&gt; &lt;/vehicle&gt; &lt;/vehicles&gt; &lt;records/&gt; &lt;/driver&gt; &lt;/drivers&gt; </code></pre> <p><strong>produces the wanted, correct result</strong>:</p> <pre><code>&lt;Vehicles&gt; &lt;vehicle&gt; &lt;vin&gt;4T1BB46K08&lt;/vin&gt; &lt;year&gt;2008&lt;/year&gt; &lt;primarydriver&gt;1&lt;/primarydriver&gt; &lt;/vehicle&gt; &lt;vehicle&gt; &lt;vin&gt;5TDZA23C06&lt;/vin&gt; &lt;year&gt;2006&lt;/year&gt; &lt;primarydriver&gt;2&lt;/primarydriver&gt; &lt;/vehicle&gt; &lt;/Vehicles&gt; </code></pre> <p><strong>Do note</strong>: The use of a modified identity rule with a parameter that passes the current driver's position. This is significantly more efficient than counting preceding siblings.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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