Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with multi-pass XSLT using node-set()
    primarykey
    data
    text
    <p>I need to display certain data in a tabular form, and would prefer to use multi-pass xslt using node-set() so that I can avoid deploying additional tools (like xsltproc). Right now, I'm able to perform the required task in two steps i.e.</p> <p>Step 1: convert XML-1 to XMl-2 using identity template (xsl:copy, using xsl:element to add dynamic elements 'dev' and 'qa`):</p> <pre><code>&lt;projectteam&gt; &lt;member&gt; &lt;name&gt;John&lt;/name&gt; &lt;role&gt;dev&lt;/role&gt; &lt;hrs&gt;100&lt;/hrs&gt; &lt;/member&gt; &lt;member&gt; &lt;name&gt;Peter&lt;/name&gt; &lt;role&gt;qa&lt;/role&gt; &lt;hrs&gt;80&lt;/hrs&gt; &lt;/member&gt; &lt;/projectteam&gt; </code></pre> <p>To</p> <pre><code>&lt;projectteam&gt; &lt;member&gt; &lt;name&gt;John&lt;/name&gt; &lt;dev&gt;100&lt;/dev&gt; &lt;/member&gt; &lt;member&gt; &lt;name&gt;Peter&lt;/name&gt; &lt;qa&gt;80&lt;/qa&gt; &lt;/member&gt; &lt;projectteam&gt; </code></pre> <p>And then, use another XSLT-FO style sheet to transform XML #2 into a PDF document with the required layout:</p> <pre> name | dev | qa | ----------------- John | 100 | | Peter| | 80 | ----------------- Total| 100 | 80 | </pre> <p>I've tried using <code>node-set()</code> (incorrectly I suppose) to combine both the steps, but it wouldn't work as the result I get is as follows:</p> <pre> name | dev | qa | ----------------- Total| 0 | 0 | </pre> <p>Stylesheet-1: converts XML-1 to XML-2, imports another stylesheet 'projDisplay.xsl', uses node-set() to invoke the imported stylesheet, but the data doesn't get displayed?</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:exslt="http://exslt.org/common" &gt; &lt;!-- import stylesheet to display XML-2 in tabular form --&gt; &lt;xsl:import href="projDisplay.xsl"/&gt; &lt;xsl:template match="/"&gt; &lt;fo:root&gt; &lt;xsl:apply-templates/&gt; &lt;/fo:root&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:variable name="newXmlData"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:variable&gt; &lt;!-- ==&gt; This is where my problem is - it goes to the template defined in --&gt; &lt;!-- projDisplay.xsl (xslt-fo, pretty big one with page layout etc. hence --&gt; &lt;!-- not included here, but it works on its own though) as I can see the --&gt; &lt;!-- table header, and an empty totals row, but non of the rows are displayed --&gt; &lt;xsl:apply-templates select="exslt:node-set($newXmlData)/projectteam" mode="display" /&gt; &lt;/xsl:template&gt; &lt;!-- replace element 'role' with a new element - role name (i.e. dev or qa) --&gt; &lt;!-- and set its value as 'hrs --&gt; &lt;xsl:template match="role"&gt; &lt;xsl:element name="{.}"&gt; &lt;xsl:value-of select="../hrs"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;!-- eliminate element 'hrs' --&gt; &lt;xsl:template match="hrs"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The commented section in the stylesheet doesn't look right to me. Any suggestions about how to correct it?</p> <p>Thanks!</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