Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL apply template outside of hierarchy using variable from current context
    primarykey
    data
    text
    <p>Let's say I have the following XML:</p> <pre><code>&lt;Zoo&gt; &lt;Keepers&gt; &lt;Keeper name="Joe" manager="Miles" /&gt; &lt;Keeper name="Bob" manager="Karen"/&gt; &lt;/Keepers&gt; &lt;Animals&gt; &lt;Animal type="tiger" keeper="Joe"/&gt; &lt;Animal type="lion" keeper="Joe"/&gt; &lt;Animal type="giraffe" keeper="Bob"/&gt; &lt;/Animals&gt; &lt;/Zoo&gt; </code></pre> <p>I basically want to use Keeper.name as a variable and then apply a template to the matching Animal nodes where Keeper.name = Animal.keeper.</p> <p>Is this possible using apply-templates or some other kind of XSL syntax?</p> <p>In my example I want to remove all Keepers managed by Miles and remove all Animal nodes kept by keepers managed by Miles, therefore I would apply blank templates.</p> <p>Here's my sudo XSL which does not quite work:</p> <pre><code>&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="*[@manager='Miles']"&gt; &lt;xsl:apply-templates select="/Zoo/Animals/Animal[@keeper=current()/@name]"/&gt; &lt;!-- apply a blank template to this Keeper --&gt; &lt;/xsl:template&gt; &lt;xsl:template match="Animal"&gt; &lt;!-- apply a blank template to this Animal --&gt; &lt;/xsl:template&gt; </code></pre> <p>My desired output XML is the following:</p> <pre><code>&lt;Zoo&gt; &lt;Keepers&gt; &lt;Keeper name="Bob" manager="Karen"/&gt; &lt;/Keepers&gt; &lt;Animals&gt; &lt;Animal type="giraffe" keeper="Bob"/&gt; &lt;/Animals&gt; &lt;/Zoo&gt; </code></pre> <p>Thank you!</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.
 

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