Xpath and XSLT-transformation problem

Discussion in 'XML' started by Pathik, Mar 30, 2007.

  1. Pathik

    Pathik Guest

    Hi All,

    Currently I am trying to convert one xml file into another xml file
    which having different format than original xml file.

    my input xml file is like:

    <?xml version="1.0" encoding="UTF-8"?>
    <MyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:n1="http://www.abc.com/resources/XML/schemas/v2_0">

    <header>
    <id>1</id>
    <test>xyz</test>
    </header>
    <n1:DataSet>
    <n1:Group REF="SE" ADJ="N"
    ABC_I="PROD" ABC_A="N100C0" ABC_IN="1"
    ABC_B_Y="2000"/>
    <n1:Series FR="M" REF="SE" ADJ="N"
    ABC_I="PROD" ABC_A="N100C0" ABC_IN="1"
    ABC_B_Y="2000">
    <n1:Obs TIME_P="199001" OBS_VALUE="101.2"/>
    <n1:Obs TIME_P="199002" OBS_VALUE="103.2"/>
    <n1:Obs TIME_P="199003" OBS_VALUE="105.2"/>
    <n1:Obs TIME_P="199004" OBS_VALUE="107.2"/>


    </n1:Series>
    </n1:DataSet>
    </MyData>

    I have to extract the Series element based on the values of ADJ,ABC_A
    etc.My intend is more clear from the following xsl file:
    The problem is that in xpath expression it doesn't recognizing
    namespace elements ie elements prefixed with n1

    Please check this and let me know where i am doing wrong.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:n1="http://www.abc.com/resources/XML/schemas/v2_0">

    <xsl:eek:utput method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:param name="REF"/>
    <xsl:param name="ADJ"/>
    <xsl:param name="ABC_I"/>
    <xsl:param name="ABC_A"/>
    <xsl:param name="ABC_IN"/>
    <xsl:param name="ABC_B_Y"/>


    <xsl:template match="/">

    <Data>
    <Table language="en">
    <Info>
    </Info>
    <Nomenclatures>
    </Nomenclatures>
    <Context>
    <Selector type="theme" code="theme1"/>
    <Selector type="domain" code="euro"/>
    <Selector type="table" code="bp_q"/>
    </Context>
    <Grid>

    <AxisZ name="REF">
    <xsl:for-each
    select="MyData/n1:DataSet/n1:Series[
    @ADJ=$ADJ and
    @ABC_A=$ABC_A and
    @ABC_IN=$ABC_I and
    @ABC_B_Y=$ABC_B_Y]">
    <xsl:element name="Position">
    <xsl:attribute name="value">
    <xsl:value-of select="@REF"/>
    </xsl:attribute>
    </xsl:element>
    <AxisY name="STS_INDICATOR">
    <xsl:element name="Position">
    <xsl:attribute name="value">
    <xsl:value-of select="@ABC_IN"/>
    </xsl:attribute>
    </xsl:element>
    <AxisX name="time">
    <xsl:for-each select="./n1:Obs">
    <xsl:element name="Position">
    <xsl:attribute name="value">
    <xsl:value-of
    select="@TIME_P"/>
    </xsl:attribute>
    </xsl:element>
    <xsl:element name="Cell">
    <xsl:attribute name="value">
    <xsl:value-of
    select="@OBS_VALUE"/>
    </xsl:attribute>
    </xsl:element>
    </xsl:for-each>
    </AxisX>
    </AxisY>
    </xsl:for-each>
    </AxisZ>
    </Grid>

    </Table>
    </Data>
    </xsl:template>
    </xsl:stylesheet>

    Thanks and Regards,
    Pathik
    Pathik, Mar 30, 2007
    #1
    1. Advertising

  2. Pathik

    Guest

    On Mar 30, 8:26 am, "Pathik" <>
    wrote:
    > my input xml file is like:


    [skipped]

    > My intend is more clear from the following xsl file:


    You've gotta be kidding. You're using 8 spaces for
    indentation and you've obviously never heard of the 78
    chars rule. Worse yet, this is a brilliant example of how
    NOT to write XSL transformations. The thing is horrible and
    you think it makes anything 'more clear'?

    > The problem is that in xpath expression it doesn't
    > recognizing namespace elements ie elements prefixed with
    > n1


    Wonderful. What makes you think that?

    > <xsl:for-each
    > select="MyData/n1:DataSet/n1:Series[
    > @ADJ=$ADJ and
    > @ABC_A=$ABC_A and
    > @ABC_IN=$ABC_I and
    > @ABC_B_Y=$ABC_B_Y]">


    I would strongly recommend learning some basic debugging
    techniques. (Hint: there's an error in this bit of code.)

    (Note: looking at awful code and pointing straight at the
    bug is something I normally charge for on per-hour basis.
    You get answers to smart and thought-provoking questions
    for free; do not expect people to do your bloody job for
    you. Keep that in mind.)

    --
    Pavel Lepin
    , Mar 30, 2007
    #2
    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. Wolfgang
    Replies:
    2
    Views:
    823
    Wolfgang
    Apr 9, 2004
  2. Wolfgang
    Replies:
    0
    Views:
    413
    Wolfgang
    Apr 6, 2004
  3. Replies:
    0
    Views:
    415
  4. Pathik
    Replies:
    2
    Views:
    499
    Martin Honnen
    Mar 27, 2007
  5. bosesuparna
    Replies:
    0
    Views:
    953
    bosesuparna
    Nov 25, 2011
Loading...

Share This Page