0

i checked the example in this link but it works for solution other way around , removees the nodes of the ID that i passed on to.

Removing XML Nodes using XSLT?

For example

<Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="example.lessson.1:v3"  >
    <dt:Header>     
        <dt:MessageId>12121212121212121</dt:MessageId>
        <dt:Timestamp>2013-01-01T00:00:00</dt:Timestamp>
        <dt:MessageType>2</dt:MessageType>
    </dt:Header>
<dt:Body >
<Rowsets>
<Rowset> 
    <Row>
        <FirstName>Michael</FirstName>
         <LastName>David</LastName>
         <Phone>1234567890</Phone>
         <ID>111111<ID>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Michael</LastName>
        <Phone>01234567890</Phone>
        <ID>222222<ID>
    </Row>
    <Row>
        <FirstName>Yang</FirstName>
        <LastName>Christina</LastName>
        <Phone>2345678901</Phone>
        <ID>333333<ID>
    </Row>
    <Row>
        <FirstName>Grey</FirstName>
        <LastName>Meredith</LastName>
        <Phone>3456789012</Phone>
        <ID>4444444<ID>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Shepherd</LastName>
        <Phone>5678901234</Phone>
        <ID>5555555<ID>
    </Row>
</Rowset>
</Rowsets>
</body>

I need to run an XSLt that will use the ID i pass and create a new xml with only that node and header and other body tags retained example if i pass 111111,222222,333333 as the input the output should be

<Message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="example.lessson.1:v3"  >

    <dt:Header>     
        <dt:MessageId>12121212121212121</dt:MessageId>
        <dt:Timestamp>2013-01-01T00:00:00</dt:Timestamp>
        <dt:MessageType>2</dt:MessageType>
    </dt:Header>
<dt:Body >
<Rowsets>
<Rowset> 
    <Row>
        <FirstName>Michael</FirstName>
         <LastName>David</LastName>
         <Phone>1234567890</Phone>
         <ID>111111<ID>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Michael</LastName>
        <Phone>01234567890</Phone>
        <ID>222222<ID>
    </Row>
    <Row>
        <FirstName>Yang</FirstName>
        <LastName>Christina</LastName>
        <Phone>2345678901</Phone<ID>333333<ID>
    </Row> 
</Rowset>
</Rowsets>
</body>

1 Answer 1

0

Use a parameter and compare the ID:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:param name="ids">111111,222222,333333</xsl:param>
    <xsl:variable name="id-sequence" select="tokenize($ids, '\s*,\s*')"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Row[not(ID = $id-sequence)]"/>
</xsl:transform>

Online at http://xsltransform.net/ejivdGF.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.