simple question

M

Mike King

I believe this is a simple question. I need a XSLT file that removes
elements from a source file. I guess the tricky part is I need to use a
variable to indicate which element to preserve. In the example below, I want
to preserve the "/root/a[1]" element where "1" would be a variable. Can
anyone help me? I'm having the hardest time figuring out template rules.

#### Input ####
<?xml version="1.0" ?>
<root>
<a id="1">
<b id="1"/>
</a>
<a id="2">
<b id="2"/>
</a>
<a id="3">
<b id="3"/>
</a>
</root>

#### Output ####
<?xml version="1.0" ?>
<root>
<a id="1">
<b id="1"/>
</a>
</root>
 
M

Martin Boehm

"/root/a[@id = '1']"

Or, with a variable:

<xsl:variable name="id" select="1" />
<xsl:apply-templates select="/root/a[@id = $id]"/>

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top