Matching parameters

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

    #1

    Matching parameters

    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>
    <reportableTe xt />
    <reportableAmou nt>4808.76</reportableAmoun t>
    <fieldTypeCode> 1</fieldTypeCode>
    </Extension>
    <FieldType>
    <description>GR OSS INCOME PD</description>
    <fieldTypeCode> 1</fieldTypeCode>
    </FieldType>
    </taxRecord>

    <xsl:variable name="field_typ e" select="fieldTy peCode"/>

    <xsl:apply-templates select="taxReco rd/Extension">
    <xsl:with-param name="field_typ e" select="$field_ type"/>
    </xsl:apply-templates>


  • Marrow

    #2
    Re: Matching parameters

    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>
    <reportableTe xt />
    <reportableAmou nt>4808.76</reportableAmoun t>
    <fieldTypeCode> 1</fieldTypeCode>
    </Extension>
    <Extension>
    <reportableTe xt />
    <reportableAmou nt>1000.05</reportableAmoun t>
    <fieldTypeCode> 2</fieldTypeCode>
    </Extension>
    <FieldType>
    <description>GR OSS INCOME PD</description>
    <fieldTypeCode> 1</fieldTypeCode>
    </FieldType>
    <FieldType>
    <description>IN COME TAX PD</description>
    <fieldTypeCode> 2</fieldTypeCode>
    </FieldType>
    </taxRecord>

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

    So if you want to list all the <Extension> element <reportableAmou nt> 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:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">
    <html>
    <body>
    <table border="1">
    <xsl:apply-templates select="taxReco rd/Extension"/>
    </table>
    </body>
    </html>
    </xsl:template>

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

    or you could consider using keys, e.g.

    == XSL2 =============== =============== =========
    <?xml version="1.0"?>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <!-- key look-up for field type meta data -->
    <xsl:key name="kFieldTyp eLookup" match="FieldTyp e" use="fieldTypeC ode"/>
    <xsl:template match="/">
    <html>
    <body>
    <table border="1">
    <xsl:apply-templates select="taxReco rd/Extension"/>
    </table>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="Extensio n">
    <tr>
    <td>
    <xsl:value-of
    select="key('kF ieldTypeLookup' ,fieldTypeCode)/description"/>
    </td>
    <td align="right">
    <xsl:value-of select="reporta bleAmount"/>
    </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" <nosendjunk@lin k.net> wrote in message
    news:1t%Ta.1186 18$Io.10108642@ newsread2.prod. itd.earthlink.n et...[color=blue]
    > 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[/color]
    are[color=blue]
    > 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>
    > <reportableTe xt />
    > <reportableAmou nt>4808.76</reportableAmoun t>
    > <fieldTypeCode> 1</fieldTypeCode>
    > </Extension>
    > <FieldType>
    > <description>GR OSS INCOME PD</description>
    > <fieldTypeCode> 1</fieldTypeCode>
    > </FieldType>
    > </taxRecord>
    >
    > <xsl:variable name="field_typ e" select="fieldTy peCode"/>
    >
    > <xsl:apply-templates select="taxReco rd/Extension">
    > <xsl:with-param name="field_typ e" select="$field_ type"/>
    > </xsl:apply-templates>
    >
    >[/color]


    Comment

    • johkar

      #3
      Re: Matching parameters

      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" <marrow-NO-@-SPAM-marrowsoft.com> wrote in message
      news:wX%Ta.838$ AN5.269339@news fep2-gui.server.ntli .net...[color=blue]
      > 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[/color]
      of[color=blue]
      > 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>
      > <reportableTe xt />
      > <reportableAmou nt>4808.76</reportableAmoun t>
      > <fieldTypeCode> 1</fieldTypeCode>
      > </Extension>
      > <Extension>
      > <reportableTe xt />
      > <reportableAmou nt>1000.05</reportableAmoun t>
      > <fieldTypeCode> 2</fieldTypeCode>
      > </Extension>
      > <FieldType>
      > <description>GR OSS INCOME PD</description>
      > <fieldTypeCode> 1</fieldTypeCode>
      > </FieldType>
      > <FieldType>
      > <description>IN COME TAX PD</description>
      > <fieldTypeCode> 2</fieldTypeCode>
      > </FieldType>
      > </taxRecord>
      >
      > == end of XML =============== =============== ===
      >
      > So if you want to list all the <Extension> element <reportableAmou nt>[/color]
      values[color=blue]
      > 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[/color]
      any[color=blue]
      > variables or parameters. For example...
      >
      > == XSL1 =============== =============== =========
      > <?xml version="1.0"?>
      > <xsl:styleshe et version="1.0"
      > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
      > <xsl:output method="html" indent="yes"/>
      > <xsl:template match="/">
      > <html>
      > <body>
      > <table border="1">
      > <xsl:apply-templates select="taxReco rd/Extension"/>
      > </table>
      > </body>
      > </html>
      > </xsl:template>
      >
      > <xsl:template match="Extensio n">
      > <tr>
      > <td>
      > <xsl:value-of select="/taxRecord/FieldType[fieldTypeCode =
      > current()/fieldTypeCode]/description"/>
      > </td>
      > <td align="right">
      > <xsl:value-of select="reporta bleAmount"/>
      > </td>
      > </tr>
      > </xsl:template>
      > </xsl:stylesheet>
      > == end of XSL1 =============== =============== ==
      >
      > or you could consider using keys, e.g.
      >
      > == XSL2 =============== =============== =========
      > <?xml version="1.0"?>
      > <xsl:styleshe et version="1.0"
      > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
      > <xsl:output method="html" indent="yes"/>
      > <!-- key look-up for field type meta data -->
      > <xsl:key name="kFieldTyp eLookup" match="FieldTyp e" use="fieldTypeC ode"/>
      > <xsl:template match="/">
      > <html>
      > <body>
      > <table border="1">
      > <xsl:apply-templates select="taxReco rd/Extension"/>
      > </table>
      > </body>
      > </html>
      > </xsl:template>
      >
      > <xsl:template match="Extensio n">
      > <tr>
      > <td>
      > <xsl:value-of
      > select="key('kF ieldTypeLookup' ,fieldTypeCode)/description"/>
      > </td>
      > <td align="right">
      > <xsl:value-of select="reporta bleAmount"/>
      > </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" <nosendjunk@lin k.net> wrote in message
      > news:1t%Ta.1186 18$Io.10108642@ newsread2.prod. itd.earthlink.n et...[color=green]
      > > I need a hint (a big hint) on how to use XSL variables and parameters.[/color][/color]
      It[color=blue][color=green]
      > > is definitely not clicking yet. Below is my XML stripped down. There[/color]
      > are[color=green]
      > > 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[/color][/color]
      Extension[color=blue][color=green]
      > > nodes and display the reportable Amount. I also need to do the same[/color][/color]
      thing[color=blue][color=green]
      > > 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>
      > > <reportableTe xt />
      > > <reportableAmou nt>4808.76</reportableAmoun t>
      > > <fieldTypeCode> 1</fieldTypeCode>
      > > </Extension>
      > > <FieldType>
      > > <description>GR OSS INCOME PD</description>
      > > <fieldTypeCode> 1</fieldTypeCode>
      > > </FieldType>
      > > </taxRecord>
      > >
      > > <xsl:variable name="field_typ e" select="fieldTy peCode"/>
      > >
      > > <xsl:apply-templates select="taxReco rd/Extension">
      > > <xsl:with-param name="field_typ e" select="$field_ type"/>
      > > </xsl:apply-templates>
      > >
      > >[/color]
      >
      >
      >[/color]


      Comment

      Working...