Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could make that a global variable by putting it outside any template:</p> <pre><code>&lt;xsl:variable name="Tokens" select="tokenize( /file/planinfo/what_transactions_are_included_overall,',')"/&gt; </code></pre> <p>then I would define another pair of templates with a mode</p> <pre><code>&lt;!-- for elements whose name is in the include list --&gt; &lt;xsl:template mode="transactionIncluded" match="*[local-name() = $Tokens]"&gt; &lt;transactions_included_overall&gt;true&lt;/transactions_included_overall&gt; &lt;/xsl:template&gt; &lt;!-- for elements whose name is *not* in the include list --&gt; &lt;xsl:template mode="transactionIncluded" match="*"&gt; &lt;transactions_included_overall&gt;false&lt;/transactions_included_overall&gt; &lt;/xsl:template&gt; </code></pre> <p>and then you can use these templates at the appropriate place</p> <pre><code>&lt;xsl:template match="data_email_national"&gt; &lt;transaction_type transaction_type="0"&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;xsl:apply-templates select="." mode="transactionIncluded" /&gt; &lt;/transaction_type&gt; &lt;/xsl:template&gt; </code></pre> <hr> <p><strong>Edit</strong></p> <p>From your comment:</p> <blockquote> <p>I've found, more than one <code>&lt;plan&gt;&lt;/plan&gt;</code> within the file, which has a single <code>&lt;planinfo&gt;</code> per <code>&lt;plan&gt;</code>. [...] i'm thinking some kind of local scope?</p> </blockquote> <p>So you have something like</p> <pre><code>&lt;file&gt; &lt;plan&gt; &lt;planinfo&gt; &lt;plan_id&gt;1&lt;/plan_id&gt; &lt;name&gt;provider100_plan1&lt;/name&gt; &lt;what_transactions_are_included_overall&gt;,,,datanormalnational,,,,,,,,&lt;/what_transactions_are_included_overall&gt; &lt;/planinfo&gt; &lt;datanormalnational&gt; &lt;cost_included&gt;-1&lt;/cost_included&gt; &lt;qty_included&gt;-1&lt;/qty_included&gt; &lt;cost_per_transaction&gt;0&lt;/cost_per_transaction&gt; &lt;/datanormalnational&gt; &lt;/plan&gt; &lt;plan&gt; &lt;planinfo&gt; &lt;plan_id&gt;1&lt;/plan_id&gt; &lt;name&gt;provider100_plan1&lt;/name&gt; &lt;what_transactions_are_included_overall&gt;,,,,dataspecialnational,,,,,,,&lt;/what_transactions_are_included_overall&gt; &lt;/planinfo&gt; &lt;dataspecialnational&gt;....&lt;/dataspecialnational&gt; &lt;/plan&gt; &lt;/file&gt; </code></pre> <p>and you want a different set of <code>what_transactions_are_included_overall</code> for each <code>plan</code>? I think you can attack this using the <a href="http://www.w3.org/TR/xslt20/#tunnel-params" rel="nofollow"><em>tunnel parameter</em></a> mechanism.</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:param name="pTransTypeDataEmail"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="info"&gt; &lt;info&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;plan_id&gt;plan.id&lt;/plan_id&gt; &lt;/info&gt; &lt;/xsl:template&gt; &lt;xsl:template match="plan"&gt; &lt;!-- delegate to the normal identity template, but populate the tunnel parameter required by the transactionIncluded template --&gt; &lt;xsl:next-match&gt; &lt;xsl:with-param name="Tokens" tunnel="yes" select="tokenize( planinfo/what_transactions_are_included_overall,',')" /&gt; &lt;/xsl:next-match&gt; &lt;/xsl:template&gt; &lt;xsl:template mode="transactionIncluded" match="*"&gt; &lt;!-- use the Tokens parameter tunnelled in from the current &lt;plan&gt; --&gt; &lt;xsl:param name="Tokens" tunnel="yes" /&gt; &lt;transactions_included_overall&gt; &lt;xsl:value-of select="if (local-name() = $Tokens) then 'true' else 'false'" /&gt; &lt;/transactions_included_overall&gt; &lt;/xsl:template&gt; &lt;xsl:template match="data_email_national"&gt; &lt;transaction_type transaction_type="0"&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;xsl:apply-templates select="." mode="transactionIncluded" /&gt; &lt;/transaction_type&gt; &lt;/xsl:template&gt; &lt;!-- and similarly for the other transaction types --&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>A tunnel parameter is automatically passed down the chain of <code>apply-template</code> calls without the need for an explicit <code>xsl:param</code>/<code>xsl:with-param</code> at every level.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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