Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Last position

From: "tshad" <tshad@----------.--->
To: NULL
Date: 3/28/2008 4:51:00 PM

I have an xsl sheet that works fine except if it is the last (or first) 
node, I want to add another set of tags.

For example with 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">
 <FORMS>
  <FORM NUM="1" FORMCODE="1004" SECCODE="1" DESC="" MAJOR="True" >
   <FIELDS>
    <OTHERFILENUMBER>692</OTHERFILENUMBER>
    <FNMA_FILENUMBER>693</FNMA_FILENUMBER>
    <SUBPROPADDRESS>3</SUBPROPADDRESS>
   </FIELDS>
  </FORM>
 </FORMS>
</REPORT>

****************************************

And the following xslt sheet.
**************************************************
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="/*">
  <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>
    <value>Some Value</value>
   </form>
  </xsl:if>
 </xsl:template>

</xsl:stylesheet>
******************************************

The result of this 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>
</REPORT>
*****************************************

What I need is to get one more set of form tags that has the attributes 
(which can be different from xml to xml) from the <FORM> tag of the xml 
file.

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>

Or it could be the whole tag:

 <form>
    <sectionNumber>1</sectionNumber>
    <primary>True</primary>
    <formName>1004</formName>
    <tagName>FormFormats</tagName>
    <flags>0</flags>
    <format>0</format>
    <value><FORM NUM="1" FORMCODE="1004" SECCODE="1" DESC="" MAJOR="True" >
    </value>
  </form>

I just need to get the information so I can put it in my database.

I thought I could do the  <xsl:if test="position()=last()"> from above, but 
it doesn't seem to work.

Thanks,

Tom 




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