![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Last position >Thread Next - Re: Last position Re: Last positionTo: 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/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
