Newbie help with transform - force output element not in input

Discussion in 'XML' started by Flomo Togba Kwele, May 2, 2007.

  1. I do not know much about xslt, but I've got a transform in place which works.
    Essentially, it takes the output of a CSV==>XML from different datasources as
    its input and creates a standardized output.

    I have recently gotten a new datasource which does not include an element which
    I do need on the output. The value will always be the same:

    <OwnerAbsentOccupied>O</OwnerAbsentOccupied>

    When I put that in the existing transform, it does appear in the output. Can
    anyone tell me how to do this?

    This is a snippet of the script:

    <xsl:template match="/csv_data_records">
    <StdAddress>
    <xsl:for-each select="@source">
    <xsl:attribute name="source">
    <xsl:value-of select="."/>
    </xsl:attribute>
    </xsl:for-each>
    <xsl:for-each select="record">
    <record>
    <xsl:for-each select="@num">
    <xsl:attribute name="num">
    <xsl:value-of select="."/>
    </xsl:attribute>
    </xsl:for-each>
    <xsl:for-each select="PRIMARY_SIC">
    <UseCode>
    <xsl:value-of select="."/>
    </UseCode>
    </xsl:for-each>
    <OwnerAbsentOccupied>O</OwnerAbsentOccupied>
    </record>
    </xsl:for-each>
    </StdAddress>
    </xsl:template>

    And the output:

    <csv_data_records source="C:\List-1259507711.TXT">
    <record num="1">
    <PRIMARY_SIC>769962</PRIMARY_SIC>
    </record>

    Thanks, Flomo
    Flomo Togba Kwele, May 2, 2007
    #1
    1. Advertising

  2. Flomo Togba Kwele wrote:

    > <xsl:template match="/csv_data_records">
    > <StdAddress>
    > <xsl:for-each select="@source">
    > <xsl:attribute name="source">
    > <xsl:value-of select="."/>
    > </xsl:attribute>
    > </xsl:for-each>
    > <xsl:for-each select="record">
    > <record>
    > <xsl:for-each select="@num">
    > <xsl:attribute name="num">
    > <xsl:value-of select="."/>
    > </xsl:attribute>
    > </xsl:for-each>
    > <xsl:for-each select="PRIMARY_SIC">
    > <UseCode>
    > <xsl:value-of select="."/>
    > </UseCode>
    > </xsl:for-each>
    > <OwnerAbsentOccupied>O</OwnerAbsentOccupied>
    > </record>
    > </xsl:for-each>
    > </StdAddress>
    > </xsl:template>
    >
    > And the output:
    >
    > <csv_data_records source="C:\List-1259507711.TXT">
    > <record num="1">
    > <PRIMARY_SIC>769962</PRIMARY_SIC>
    > </record>


    A literal result element such as the OwnerAbsentOccupied element you
    have above will be output literally so there should not be a problem.
    However the root created above is StdAddress and not csv_data_records so
    the alleged output does not fit the XSLT you present.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 2, 2007
    #2
    1. Advertising

  3. Martin,

    Thanks for the reply. You are absolutely right. The two documents did not
    match. It shows that sometimes I dont' really know what I am doing.

    I got it to work, due to your prodding.

    Thanks, Flomo
    Flomo Togba Kwele, May 2, 2007
    #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. Kolossi
    Replies:
    7
    Views:
    1,093
    Kolossi
    Sep 14, 2005
  2. Lukas
    Replies:
    3
    Views:
    786
    spiff
    Nov 10, 2005
  3. edgekaos
    Replies:
    3
    Views:
    526
    Andrey Tarasevich
    Nov 4, 2005
  4. ComicCaper
    Replies:
    2
    Views:
    334
    ComicCaper
    May 10, 2006
  5. HANM
    Replies:
    2
    Views:
    697
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page