Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Last position

From: "tshad" <tshad@----------.--->
To: NULL
Date: 3/31/2008 10:42:00 AM

I am going to respond to this twice, only because I don't want to confuse 
the issue and I want to change example a little to explain my 2nd question 
on this.

"Martin Honnen" <mahotrash@y...> wrote in message 
news:u0qKeqZkIHA.5820@T......
> tshad wrote:
>
>> So the last form would look something like:
>>
>>  <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>
>
> This adds an additional form element

Right.

That is what I am trying to do.  Get another form element where the 
important field would only be the <value> which gives me the all the 
attributes in the
>
> <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: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>
>

Worked perfectly.

I am confused as to why it did, however.

In my file, I had:

      <xsl:apply-templates select="FORMS/FORM"/>

which doesn't work - doesn't seem to handle the "xsl:if test" so I don't get 
the extra form element.  But it works perfectly for the other 3.  It 
displayes the 3 form elements just not the extra one inside the test.

You changed it to:

      <xsl:apply-templates select="FORMS/FORM/FIELDS/*"/>

and it handles it fine.  I thought that "FORMS/FORM" would handle all the 
child elements.  Why do I need the /FIELDS/* ?

Also,

Yours indents perfectly:

mine just appends each tag one after another.  Yet I also have the 
"indent=yes" in my xsl:output.

<?xml version="1.0" encoding="utf-8"?>
<REPORT>

    <form><sectionNumber>1</sectionNumber><primary>True</primary><formName>1004</formName><tagName>OTHERFILENUMBER</tagName><flags>0</flags><format>0</format><value>692</value></form>
    <form><sectionNumber>1</sectionNumber><primary>True</primary><formName>1004</formName><tagName>FNMA_FILENUMBER</tagName><flags>0</flags><format>0</format><value>693</value></form>
    <form><sectionNumber>1</sectionNumber><primary>True</primary><formName>1004</formName><tagName>SUBPROPADDRESS</tagName><flags>0</flags><format>0</format><value>3</value></form>

  </REPORT>

why is that?

This last question is similar to the one I am going to ask with a more 
expanded example:

In this sample, we have 2 templates and 2 apply-templates.

When we say:

<xsl:apply-templates select="FORMS/FORM/FIELDS/*"/>

How does it know to use the 1st template?

And how does:

 <xsl:apply-templates select="../../@*"/>

know to use the last template since there are no template names or ids?

Thanks,

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




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