Newbie help with transform - force output element not in input

  • Thread starter Flomo Togba Kwele
  • Start date
F

Flomo Togba Kwele

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
 
M

Martin Honnen

Flomo said:
<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.
 
F

Flomo Togba Kwele

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top