simple question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike King

    #1

    simple question

    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>


  • Martin Boehm

    #2
    Re: simple question

    "Mike King" <emailMK@excite .com> wrote in message
    news:vo5q134mht 33cc@corp.super news.com

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

    Or, with a variable:

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

    Martin


    Comment

    Working...