![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Combining elements Combining elementsTo: NULL Date: 3/31/2008 7:00:00 PM
I have a file that can have comments that are spread among mulitple elements
in various formats (comment1,comment2, comment3...) or (comment_1,comment2,
comment3...) or (comment, comment1, comment2...)
I need to concatenate them in my xslt sheet.
I already have a sheet that works, and need to add this in. If it is a
problem, then I will just do it in my DataSet - but I want to get as much
done with the xslt sheet as possible.
I have the following xslt that I have stripped down that works real well
that Martin helped me put together:
**********************************************************
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="REPORT">
<xsl:copy>
<xsl:apply-templates select="FORMS/FORM/FIELDS/*"/>
<xsl:apply-templates select="FORMS/FORM/attachments/attachment"/>
</xsl:copy>
</xsl:template>
<xsl:template match="FIELDS/*">
<form>
<sectionNumber>
<xsl:text>0</xsl:text>
</sectionNumber>
<primary>True</primary>
<formName>
<xsl:value-of select="../../@FORMCODE"/>
</formName>
<tagName>
<xsl:value-of select="name()"/>
</tagName>
<flags>0</flags>
<format>0</format>
<value>
<xsl:value-of select="."/>
</value>
</form>
<xsl:if test="position()=last()">
<form>
<sectionNumber>
<xsl:value-of select="../../@SECCODE"/>
</sectionNumber>
<primary>True</primary>
<formName>
<xsl:value-of select="../../@FORMCODE"/>
</formName>
<tagName>FormFormats</tagName>
<flags>0</flags>
<format>0</format>
<value>
<xsl:apply-templates select="../../@*"/>
</value>
</form>
</xsl:if>
</xsl:template>
<xsl:template match="FORM/@*">
<xsl:value-of select="concat(name(), '=', .)"/>
<xsl:if test="position() != last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
**********************************************************
To start out with I would like to do is test the <tagName> and if it ends
with a "_1" and if so loop through the next siblings to see if there are any
more that start with the same name (minus the number) and concatenate them.
That would be too hard. But how do I tell it not to ignore those that I
have concatenated? I don't want to change the structure too much as it
works now for a variety of types of elements.
The sample xml file looks like:
*********************************************************
<?xml version="1.0" encoding="utf-8"?>
<REPORT VERSION="1.10" FILENUM="" DESCRIPTION="Form Utility XML: 3/18/2008
12:27:13 PM" MAJORFORM="1004">
<FORMS>
<FORM NUM="1" FORMCODE="1004" SECCODE="1" DESC="" MAJOR="True" >
<FIELDS>
<OTHERFILENUMBER>692</OTHERFILENUMBER>
<FNMA_FILENUMBER>693</FNMA_FILENUMBER>
<SUBPROPADDRESS>3</SUBPROPADDRESS>
<SCMCOMMENTS_1>This is a test line 1</SCMCOMMENTS_1>
<SCMCOMMENTS_2>This is a test line 2</SCMCOMMENTS_2>
<SCMCOMMENTS_3>This is a test line 3</SCMCOMMENTS_3>
<SCMCOMMENTS_4>This is a test line 4</SCMCOMMENTS_4>
</FIELDS>
</FORM>
</FORMS>
</REPORT>
*********************************************************
This file creates this result:
*********************************************************
<?xml version="1.0" encoding="utf-8"?>
<REPORT>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>OTHERFILENUMBER</tagName>
<flags>0</flags>
<format>0</format>
<value>692</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>FNMA_FILENUMBER</tagName>
<flags>0</flags>
<format>0</format>
<value>693</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SUBPROPADDRESS</tagName>
<flags>0</flags>
<format>0</format>
<value>3</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SCMCOMMENTS_1</tagName>
<flags>0</flags>
<format>0</format>
<value>This is a test line 1</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SCMCOMMENTS_2</tagName>
<flags>0</flags>
<format>0</format>
<value>This is a test line 2</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SCMCOMMENTS_3</tagName>
<flags>0</flags>
<format>0</format>
<value>This is a test line 3</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SCMCOMMENTS_4</tagName>
<flags>0</flags>
<format>0</format>
<value>This is a test line 4</value>
</form>
<form>
<sectionNumber>1</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>FormFormats</tagName>
<flags>0</flags>
<format>0</format>
<value>NUM=1 FORMCODE=1004 SECCODE=1 DESC= MAJOR=True</value>
</form>
</REPORT>
*********************************************************
What I would like the result to look like is:
************************************************************
<?xml version="1.0" encoding="utf-8"?>
<REPORT>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>OTHERFILENUMBER</tagName>
<flags>0</flags>
<format>0</format>
<value>692</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>FNMA_FILENUMBER</tagName>
<flags>0</flags>
<format>0</format>
<value>693</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SUBPROPADDRESS</tagName>
<flags>0</flags>
<format>0</format>
<value>3</value>
</form>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>SCMCOMMENTS_1</tagName>
<flags>0</flags>
<format>0</format>
<value>This is a test line 1 This is a test line 2 This is a test line 3
This is a test line 4</value>
</form>
<form>
<sectionNumber>1</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>FormFormats</tagName>
<flags>0</flags>
<format>0</format>
<value>NUM=1 FORMCODE=1004 SECCODE=1 DESC= MAJOR=True</value>
</form>
</REPORT>
*******************************************************
There could be 3 comments or there could be 15.
Thanks,
Tom
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
