Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Combining elements >Thread Next - Re: Combining elements Re: Combining elementsTo: NULL Date: 4/1/2008 2:14:00 PM
tshad wrote:
>
> 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>
Here is an adapted stylesheet that creates the output described above:
<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/*[not(starts-with(name(), 'SCMCOMMENTS'))]"/>
<form>
<sectionNumber>0</sectionNumber>
<primary>True</primary>
<formName><xsl:value-of select="FORMS/FORM/@FORMCODE"/></formName>
<tagName>SCMCOMMENTS_1</tagName>
<flags>0</flags>
<format>0</format>
<value>
<xsl:apply-templates
select="FORMS/FORM/FIELDS/*[starts-with(name(), 'SCMCOMMENTS')]"/>
</value>
</form>
<form>
<sectionNumber>
<xsl:value-of select="FORMS/FORM/@SECCODE"/>
</sectionNumber>
<primary>True</primary>
<formName>
<xsl:value-of select="FORMS/FORM/@FORMCODE"/>
</formName>
<tagName>FormFormats</tagName>
<flags>0</flags>
<format>0</format>
<value>
<xsl:apply-templates select="FORMS/FORM/@*"/>
</value>
</form>
<xsl:apply-templates select="FORMS/FORM/attachments/attachment"/>
</xsl:copy>
</xsl:template>
<xsl:template match="FIELDS/*[not(starts-with(name(), 'SCMCOMMENTS'))]">
<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:template>
<xsl:template match="FIELDS/*[starts-with(name(), 'SCMCOMMENTS')]">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text> </xsl:text>
</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>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
