Matching parameters

Discussion in 'XML' started by johkar, Jul 25, 2003.

  1. johkar

    johkar Guest

    I need a hint (a big hint) on how to use XSL variables and parameters. It
    is definitely not clicking yet. Below is my XML stripped down. There are
    multiple Extension nodes and multiple FieldType nodes. Notice that the
    fieldTypeCode nodes match in value. I need to pass in a fieldTypeCode
    (fieldTypeCode='1') to a template which will iterate through the Extension
    nodes and display the reportable Amount. I also need to do the same thing
    to display the corresponding label which is the description node within
    FieldType. I.E. GROSS INCOME PD 4808.76.

    <?xml version="1.0" encoding="UTF-8"?>
    <taxRecord>
    <Extension>
    <reportableText />
    <reportableAmount>4808.76</reportableAmount>
    <fieldTypeCode>1</fieldTypeCode>
    </Extension>
    <FieldType>
    <description>GROSS INCOME PD</description>
    <fieldTypeCode>1</fieldTypeCode>
    </FieldType>
    </taxRecord>

    <xsl:variable name="field_type" select="fieldTypeCode"/>

    <xsl:apply-templates select="taxRecord/Extension">
    <xsl:with-param name="field_type" select="$field_type"/>
    </xsl:apply-templates>
    johkar, Jul 25, 2003
    #1
    1. Advertising

  2. johkar

    Marrow Guest

    Hi,

    I think you've stripped down your XML a little too far ;) Sometimes when
    there is only one example item it is difficult to see the overall purpose of
    the data against possible meta-data.

    At a guess, a slightly less stripped down XML might look like?...

    == XML ========================================
    <?xml version="1.0"?>
    <taxRecord>
    <Extension>
    <reportableText />
    <reportableAmount>4808.76</reportableAmount>
    <fieldTypeCode>1</fieldTypeCode>
    </Extension>
    <Extension>
    <reportableText />
    <reportableAmount>1000.05</reportableAmount>
    <fieldTypeCode>2</fieldTypeCode>
    </Extension>
    <FieldType>
    <description>GROSS INCOME PD</description>
    <fieldTypeCode>1</fieldTypeCode>
    </FieldType>
    <FieldType>
    <description>INCOME TAX PD</description>
    <fieldTypeCode>2</fieldTypeCode>
    </FieldType>
    </taxRecord>

    == end of XML =================================

    So if you want to list all the <Extension> element <reportableAmount> values
    along with the meta data for the corresponding field types, e.g.

    GROSS INCOME PD 4808.76
    INCOME TAX PD 1000.05

    If that is what you are trying to do - then you really don't need to use any
    variables or parameters. For example...

    == XSL1 =======================================
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" indent="yes"/>
    <xsl:template match="/">
    <html>
    <body>
    <table border="1">
    <xsl:apply-templates select="taxRecord/Extension"/>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="Extension">
    <tr>
    <td>
    <xsl:value-of select="/taxRecord/FieldType[fieldTypeCode =
    current()/fieldTypeCode]/description"/>
    </td>
    <td align="right">
    <xsl:value-of select="reportableAmount"/>
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>
    == end of XSL1 ================================

    or you could consider using keys, e.g.

    == XSL2 =======================================
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" indent="yes"/>
    <!-- key look-up for field type meta data -->
    <xsl:key name="kFieldTypeLookup" match="FieldType" use="fieldTypeCode"/>
    <xsl:template match="/">
    <html>
    <body>
    <table border="1">
    <xsl:apply-templates select="taxRecord/Extension"/>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="Extension">
    <tr>
    <td>
    <xsl:value-of
    select="key('kFieldTypeLookup',fieldTypeCode)/description"/>
    </td>
    <td align="right">
    <xsl:value-of select="reportableAmount"/>
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>
    == end of XSL2 ================================

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "johkar" <> wrote in message
    news:1t%Ta.118618$...
    > I need a hint (a big hint) on how to use XSL variables and parameters. It
    > is definitely not clicking yet. Below is my XML stripped down. There

    are
    > multiple Extension nodes and multiple FieldType nodes. Notice that the
    > fieldTypeCode nodes match in value. I need to pass in a fieldTypeCode
    > (fieldTypeCode='1') to a template which will iterate through the Extension
    > nodes and display the reportable Amount. I also need to do the same thing
    > to display the corresponding label which is the description node within
    > FieldType. I.E. GROSS INCOME PD 4808.76.
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <taxRecord>
    > <Extension>
    > <reportableText />
    > <reportableAmount>4808.76</reportableAmount>
    > <fieldTypeCode>1</fieldTypeCode>
    > </Extension>
    > <FieldType>
    > <description>GROSS INCOME PD</description>
    > <fieldTypeCode>1</fieldTypeCode>
    > </FieldType>
    > </taxRecord>
    >
    > <xsl:variable name="field_type" select="fieldTypeCode"/>
    >
    > <xsl:apply-templates select="taxRecord/Extension">
    > <xsl:with-param name="field_type" select="$field_type"/>
    > </xsl:apply-templates>
    >
    >
    Marrow, Jul 25, 2003
    #2
    1. Advertising

  3. johkar

    johkar Guest

    Thanks, I knew I was making a mountain out of a molehill. I have ordered a
    couple of XSL books. I appreciate your help.

    J.

    "Marrow" <> wrote in message
    news:wX%Ta.838$...
    > Hi,
    >
    > I think you've stripped down your XML a little too far ;) Sometimes when
    > there is only one example item it is difficult to see the overall purpose

    of
    > the data against possible meta-data.
    >
    > At a guess, a slightly less stripped down XML might look like?...
    >
    > == XML ========================================
    > <?xml version="1.0"?>
    > <taxRecord>
    > <Extension>
    > <reportableText />
    > <reportableAmount>4808.76</reportableAmount>
    > <fieldTypeCode>1</fieldTypeCode>
    > </Extension>
    > <Extension>
    > <reportableText />
    > <reportableAmount>1000.05</reportableAmount>
    > <fieldTypeCode>2</fieldTypeCode>
    > </Extension>
    > <FieldType>
    > <description>GROSS INCOME PD</description>
    > <fieldTypeCode>1</fieldTypeCode>
    > </FieldType>
    > <FieldType>
    > <description>INCOME TAX PD</description>
    > <fieldTypeCode>2</fieldTypeCode>
    > </FieldType>
    > </taxRecord>
    >
    > == end of XML =================================
    >
    > So if you want to list all the <Extension> element <reportableAmount>

    values
    > along with the meta data for the corresponding field types, e.g.
    >
    > GROSS INCOME PD 4808.76
    > INCOME TAX PD 1000.05
    >
    > If that is what you are trying to do - then you really don't need to use

    any
    > variables or parameters. For example...
    >
    > == XSL1 =======================================
    > <?xml version="1.0"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="html" indent="yes"/>
    > <xsl:template match="/">
    > <html>
    > <body>
    > <table border="1">
    > <xsl:apply-templates select="taxRecord/Extension"/>
    > </table>
    > </body>
    > </html>
    > </xsl:template>
    >
    > <xsl:template match="Extension">
    > <tr>
    > <td>
    > <xsl:value-of select="/taxRecord/FieldType[fieldTypeCode =
    > current()/fieldTypeCode]/description"/>
    > </td>
    > <td align="right">
    > <xsl:value-of select="reportableAmount"/>
    > </td>
    > </tr>
    > </xsl:template>
    > </xsl:stylesheet>
    > == end of XSL1 ================================
    >
    > or you could consider using keys, e.g.
    >
    > == XSL2 =======================================
    > <?xml version="1.0"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="html" indent="yes"/>
    > <!-- key look-up for field type meta data -->
    > <xsl:key name="kFieldTypeLookup" match="FieldType" use="fieldTypeCode"/>
    > <xsl:template match="/">
    > <html>
    > <body>
    > <table border="1">
    > <xsl:apply-templates select="taxRecord/Extension"/>
    > </table>
    > </body>
    > </html>
    > </xsl:template>
    >
    > <xsl:template match="Extension">
    > <tr>
    > <td>
    > <xsl:value-of
    > select="key('kFieldTypeLookup',fieldTypeCode)/description"/>
    > </td>
    > <td align="right">
    > <xsl:value-of select="reportableAmount"/>
    > </td>
    > </tr>
    > </xsl:template>
    > </xsl:stylesheet>
    > == end of XSL2 ================================
    >
    > Hope this helps
    > Marrow
    > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    > http://www.topxml.com/Xselerator
    >
    >
    > "johkar" <> wrote in message
    > news:1t%Ta.118618$...
    > > I need a hint (a big hint) on how to use XSL variables and parameters.

    It
    > > is definitely not clicking yet. Below is my XML stripped down. There

    > are
    > > multiple Extension nodes and multiple FieldType nodes. Notice that the
    > > fieldTypeCode nodes match in value. I need to pass in a fieldTypeCode
    > > (fieldTypeCode='1') to a template which will iterate through the

    Extension
    > > nodes and display the reportable Amount. I also need to do the same

    thing
    > > to display the corresponding label which is the description node within
    > > FieldType. I.E. GROSS INCOME PD 4808.76.
    > >
    > > <?xml version="1.0" encoding="UTF-8"?>
    > > <taxRecord>
    > > <Extension>
    > > <reportableText />
    > > <reportableAmount>4808.76</reportableAmount>
    > > <fieldTypeCode>1</fieldTypeCode>
    > > </Extension>
    > > <FieldType>
    > > <description>GROSS INCOME PD</description>
    > > <fieldTypeCode>1</fieldTypeCode>
    > > </FieldType>
    > > </taxRecord>
    > >
    > > <xsl:variable name="field_type" select="fieldTypeCode"/>
    > >
    > > <xsl:apply-templates select="taxRecord/Extension">
    > > <xsl:with-param name="field_type" select="$field_type"/>
    > > </xsl:apply-templates>
    > >
    > >

    >
    >
    >
    johkar, Jul 25, 2003
    #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. Jonck van der Kogel
    Replies:
    2
    Views:
    964
    Jonck van der Kogel
    May 27, 2004
  2. spakka
    Replies:
    3
    Views:
    332
    spakka
    Sep 11, 2005
  3. Jason
    Replies:
    2
    Views:
    492
    Jonathan Mcdougall
    May 13, 2006
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    220
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    214
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page