Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Loop through children

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 3/29/2008 8:51:00 AM



"tshad" <tshad@d...> wrote in message 
news:#lJnknRkIHA.4120@T......
> That worked really well.
>
> Why did you do the:
>
>       <xsl:apply-templates select="FORMS/FORM/FIELDS/*"/>
>
> And then the:
>
>   <xsl:template match="FIELDS/*">
>
> Doesn't the select already get a node set that is already just the nodes 
> below the FIELDS tag?
>
> IF that was the case (which it may not be), couldn't you just have done:
>
>   <xsl:template match="*">
>
> Thanks,
>
> Tom
>
> "Martin Honnen" <mahotrash@y...> wrote in message 
> news:%230kiCFPkIHA.4480@T......
>> tshad wrote:
>>> If I have the following xml:
>>>
>>> <?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">
>>>   <ORDER></ORDER>
>>>   <TRACKING></TRACKING>
>>>   <FORMS>
>>>     <FORM NUM="1" FORMCODE="1004" SECCODE="1" DESC="" MAJOR="True" >
>>>       <FIELDS>
>>>         <OTHERFILENUMBER>692</OTHERFILENUMBER>
>>>         <FNMA_FILENUMBER>693</FNMA_FILENUMBER>
>>>         <SUBPROPADDRESS>3</SUBPROPADDRESS>
>>>       </FIELDS>
>>>       <FORMPHOTOS></FORMPHOTOS>
>>>       <ATTACHMENTS></ATTACHMENTS>
>>>     </FORM>
>>>   </FORMS>
>>> </REPORT>
>>>
>>> I have can have about 200 nodes under the <FIELDS> node.
>>>
>>> Each node has it's own name.
>>>
>>> What I am looking for is to build an style sheet that loops through the 
>>> children and creates a set of nodes that would look something like:
>>>
>>> <?xml version="1.0" encoding="utf-8"?>
>>> <REPORT>
>>>    <form>
>>>       <sectionNumber>1</sectionNumber>
>>>       <primary>True</primary>
>>>       <formName>1004</formName>
>>>       <tagName>OTHERFILENUMBER</tagName>
>>>       <value>692</value>
>>>    <form>
>>>    <form>
>>>       <sectionNumber>1</sectionNumber>
>>>       <primary>True</primary>
>>>       <formName>1004</formName>
>>>       <tagName>FNMA_FILENUMBER</tagName>
>>>       <value>693</value>
>>>    <form>
>>>    <form>
>>>       <sectionNumber>1</sectionNumber>
>>>       <primary>True</primary>
>>>       <formName>1004</formName>
>>>       <tagName>SUBPROPADDRESS</tagName>
>>>       <value>SUBPROPADDRESS</value>
>>>    <form>
>>> </REPORT>
>>
>> Here is a stylesheet that performs the transformation:
>>
>> <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:copy>
>>   </xsl:template>
>>
>>   <xsl:template match="FIELDS/*">
>>     <form>
>>       <sectionNumber><xsl:value-of 
>> select="../../@SECCODE"/></sectionNumber>
>>       <primary>True</primary>
>>       <formName><xsl:value-of select="../../@FORMCODE"/></formName>
>>       <tagName><xsl:value-of select="name()"/></tagName>
>>       <value><xsl:value-of select="."/></value>
>>     </form>
>>   </xsl:template>
>>
>> </xsl:stylesheet>
>>
>>
>>
>> -- 
>>
>> Martin Honnen --- MVP XML
>> http://JavaScript.FAQTs.com/
>
>
Ignore my previous answer, I misread your question. The match needs to be 
FIELDS/* so that it matches solely children of the FIELDS element, * alone 
would match any element.

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name 



transparent
Print
Mail
Digg
delicious
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