How to output the all the ancestor and their attribute of an element

Discussion in 'XML' started by ai2003lian@yahoo.com, Feb 3, 2005.

  1. Guest

    Assuming I have the following two xml file:

    source.xml:

    <AllFields>
    <Group name="G1">
    <Field fieldName="f1">Value1</Field>
    <Field fieldName="f2">Value2</Field>
    <Field fieldName="f3">Value3</Field>
    </Group>
    <Group name="G2">
    <Field fieldName="f4">Value4</Field>
    <Field fieldName="f5">Value5</Field>
    <Field fieldName="f6">Value6</Field>
    </Group>
    </AllFields>

    requirement.xml:

    <RequiredFields>
    <FieldName>f1</FieldName>
    <FieldName>f3</FieldName>
    <FieldName>f6</FieldName>
    </RequiredFields>

    The requirement.xml defines which field will go to the output XML. How
    could I use XSLT to get the following output:

    <AllFields>
    <Group name="G1">
    <Field fieldName="f1">Value1</Field>
    <Field fieldName="f3">Value3</Field>
    </Group>
    <Group name="G2">
    <Field fieldName="f6">Value6</Field>
    </Group>
    </AllFields>

    Thanks your help in advance!
     
    , Feb 3, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Tempore 17:16:45, die Thursday 03 February 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > Assuming I have the following two xml file:
    >
    > source.xml:
    >
    > <AllFields>
    > <Group name="G1">
    > <Field fieldName="f1">Value1</Field>
    > <Field fieldName="f2">Value2</Field>
    > <Field fieldName="f3">Value3</Field>
    > </Group>
    > <Group name="G2">
    > <Field fieldName="f4">Value4</Field>
    > <Field fieldName="f5">Value5</Field>
    > <Field fieldName="f6">Value6</Field>
    > </Group>
    > </AllFields>
    >
    > requirement.xml:
    >
    > <RequiredFields>
    > <FieldName>f1</FieldName>
    > <FieldName>f3</FieldName>
    > <FieldName>f6</FieldName>
    > </RequiredFields>
    >
    > The requirement.xml defines which field will go to the output XML. How
    > could I use XSLT to get the following output:
    >
    > <AllFields>
    > <Group name="G1">
    > <Field fieldName="f1">Value1</Field>
    > <Field fieldName="f3">Value3</Field>
    > </Group>
    > <Group name="G2">
    > <Field fieldName="f6">Value6</Field>
    > </Group>
    > </AllFields>

    Hi,

    You could use some stylesheet like this:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:eek:utput indent="yes"/>

    <xsl:template match="node()|@*">
    <xsl:if test="not(self::Field) or @fieldName=document('requirement.xml')/*/FieldName">
    <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>



    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    "Et ipsa scientia potestas est" - Francis Bacon , Meditationes sacrae
     
    Joris Gillis, Feb 3, 2005
    #2
    1. Advertising

  3. Guest

    Thanks! it works!
     
    , Feb 3, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ognen Ivanovski
    Replies:
    0
    Views:
    955
    Ognen Ivanovski
    Jul 15, 2003
  2. Replies:
    6
    Views:
    544
  3. Ebenezer
    Replies:
    7
    Views:
    869
    Richard Tobin
    Oct 25, 2008
  4. Amir Karger
    Replies:
    9
    Views:
    133
    Tassilo v. Parseval
    Dec 10, 2003
  5. harryajh
    Replies:
    4
    Views:
    275
    Thomas 'PointedEars' Lahn
    Feb 1, 2008
Loading...

Share This Page