![]() |
![]() | ![]() | ![]() | 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 11:06:00 AM
This is the 2nd question using the same answer you gave here.
But what I am doing is adding one more template (which is what I took out to
simplify the question originally) which doesn't work with this answer. I
assume this is because of the change in the apply-template (FORMS/FORM) to
(FORMS/FORM/FIELDS/*).
"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
>
> <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>
With a change where I add one more template:
*****************************************
<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"/>
</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>
<flags>0</flags>
<format>0</format>
<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>
<xsl:apply-templates select="../../@*"/>
</form>
</xsl:if>
</xsl:template>
<xsl:template match="attachments/attachment">
<attachment>
<key>
<xsl:value-of select="@key"/>
</key>
<type>
<xsl:value-of select="@type"/>
</type>
<label>
<xsl:value-of select="@label"/>
</label>
<imageFormat>
<xsl:value-of select="image/binary/@format"/>
</imageFormat>
<imageText>
<xsl:value-of select="image/binary/text()"/>
</imageText>
<thumbnailFormat>
<xsl:value-of select="thumbnail/binary/@format"/>
</thumbnailFormat>
<thumbnailImage>
<xsl:value-of select="thumbnail/binary/text()"/>
</thumbnailImage>
<sourceFormat>
<xsl:value-of select="source/@format"/>
</sourceFormat>
<sourceKey>
<xsl:value-of select="source/@key"/>
</sourceKey>
<sourceText>
<xsl:value-of select="source/binary/text()"/>
</sourceText>
</attachment>
</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>
********************************************
The xml file is:
***********************************************
<?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>
<attachment key="db8d208f-b049-4caa-bac0-eeb4cf9007d6" type="photo"
label="Comparable Sale #1">
<image>
<binary xmlns:dt="urn:schemas-microsoft-com:datatypes"
dt:dt="bin.base64" format="jpeg">/9j/4AAQSkZJRgA</binary>
</image>
<thumbnail>
<binary xmlns:dt="urn:schemas-microsoft-com:datatypes"
dt:dt="bin.base64" format="jpeg">/9j/4AAQSkZ</binary>
</thumbnail>
</attachment>
<attachment key="560ff252-882d-4d3e-9e0c-aa1cb7c38952" type="photo"
label="Comparable Sale #2">
<image>
<binary xmlns:dt="urn:schemas-microsoft-com:datatypes"
dt:dt="bin.base64" format="jpeg">/9j/4AAQSkZJR</binary>
</image>
<thumbnail>
<binary xmlns:dt="urn:schemas-microsoft-com:datatypes"
dt:dt="bin.base64" format="jpeg">/9j/4AAQSkZJR</binary>
</thumbnail>
</attachment>
</attachments>
</FORM>
</FORMS>
</REPORT>
***************************************************************
And my result is:
*****************************************************************
<?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>
<attachment><key>db8d208f-b049-4caa-bac0-eeb4cf9007d6</key><type>photo</type><label>Comparable
Sale
#1</label><imageFormat>jpeg</imageFormat><imageText>/9j/4AAQSkZJRgA</imageText><thumbnailFormat>jpeg</thumbnailFormat><thumbnailImage>/9j/4AAQSkZ</thumbnailImage><sourceFormat></sourceFormat><sourceKey></sourceKey><sourceText></sourceText></attachment>
<attachment><key>560ff252-882d-4d3e-9e0c-aa1cb7c38952</key><type>photo</type><label>Comparable
Sale
#2</label><imageFormat>jpeg</imageFormat><imageText>/9j/4AAQSkZJR</imageText><thumbnailFormat>jpeg</thumbnailFormat><thumbnailImage>/9j/4AAQSkZJR</thumbnailImage><sourceFormat></sourceFormat><sourceKey></sourceKey><sourceText></sourceText></attachment>
</REPORT>
*****************************************************************
Of course, I still have the same problem from my old example where there is
no indenting.
So I changed the apply-templates to:
********************************************************
<xsl:template match="REPORT">
<xsl:copy>
<xsl:apply-templates select="FORMS/FORM/FIELDS/*"/>
<xsl:apply-templates select="FORMS/FORM"/>
</xsl:copy>
</xsl:template>
********************************************************
And it almost worked, but it gave me an extra set of form elements: mine
(with no indents) and yours(indented and the extra form element - but the
last </form> didn't seem to indent).
******************************************************************
<?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>
<form>
<sectionNumber>1</sectionNumber>
<primary>True</primary>
<formName>1004</formName>
<tagName>FormFormats</tagName>
<flags>0</flags>
<format>0</format>NUM=1 FORMCODE=1004 SECCODE=1 DESC= MAJOR=True</form>
<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>
<attachment><key>db8d208f-b049-4caa-bac0-eeb4cf9007d6</key><type>photo</type><label>Comparable
Sale
#1</label><imageFormat>jpeg</imageFormat><imageText>/9j/4AAQSkZJRgA</imageText><thumbnailFormat>jpeg</thumbnailFormat><thumbnailImage>/9j/4AAQSkZ</thumbnailImage><sourceFormat></sourceFormat><sourceKey></sourceKey><sourceText></sourceText></attachment>
<attachment><key>560ff252-882d-4d3e-9e0c-aa1cb7c38952</key><type>photo</type><label>Comparable
Sale
#2</label><imageFormat>jpeg</imageFormat><imageText>/9j/4AAQSkZJR</imageText><thumbnailFormat>jpeg</thumbnailFormat><thumbnailImage>/9j/4AAQSkZJR</thumbnailImage><sourceFormat></sourceFormat><sourceKey></sourceKey><sourceText></sourceText></attachment>
</REPORT>
******************************************************************
So close...
Thanks,
Tom
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
