Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Last position

From: "tshad" <tshad@----------.--->
To: 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/ 




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