Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Combining elements

From: "tshad" <tshad@----------.--->
To: NULL
Date: 4/11/2008 10:41:00 AM


"Martin Honnen" <mahotrash@y...> wrote in message 
news:eoQPgH$kIHA.6032@T......
> 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>
>
>

How would I modify the above script to just look at the <FORM> that has 
@MAJOR = TRUE?

I have the following xml:

The sample xml file that looks almost the same as my other one but also has 
another FORM in it that doesn't have @MAJOR = true and it looks something 
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>
  <FORM NUM="1" FORMCODE="GA1" MAJOR="False" FONTNAME="Arial" >
     <FIELDS>
        <FOOTER1>Form GA1 - "WinTOTAL" appraisal software by a la mode, 
inc. - 1-800-ALAMODE</FOOTER1>
        <SUBPROPADDRESS>10 KENSINGTON CT</SUBPROPADDRESS>
        <SUBLEGALDESCRIP>BLOCK-2006 LOT- 6.0205 MSA - 
35644</SUBLEGALDESCRIP>
        <SUBCOMBADDRESS>TENAFLY, NJ 07670-2872</SUBCOMBADDRESS>
        <SUBLENCLIENT>CITI HOME EQUITY</SUBLENCLIENT>
     </FIELDS
   </Form>
 </FORMS>
</REPORT>
*********************************************************

How would I change your sheet to only look the ones with @major = true?  Or 
apply all the same rules as before only to this one.  Then handle the 2nd 
Form separately, say a test on @FORMCODE="GA1"

Thanks,

Tom
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent