?
Solved

Simulating counting variable in XSLT

Posted on 2003-02-26
15
Medium Priority
?
461 Views
Last Modified: 2013-11-18
All.

I have  a problem where I am attempting to transform some data but at the end of the process I need to know how many segements have been created as part of the transformation process.

Ex:  I have data where I can have a random # of child packages per shipment (each shipment consists of 1 or more child packages).

<PACKAGE id=1 shipment=A>
<PACKAGE id=2 shipment=A>
<PACKAGE id=3 shipment=A>
<PACKAGE id=4 shipment=B>
<PACKAGE id=5 shipment=C>
<PACKAGE id=6 shipment=C>

The situation is for every shipment I create an element like:
  <SHIPMENT packagecount="count-of(children)">

And for each pacakge I have to create sub-element.

<PACKAGE id=1 /><PACKAGE id=2 /><PACKAGE id=3 /></SHIPMENT>

....et cetera.

I need a total count of the elements I've created computed something like this:  

  Number of shipment elements+((Number of Package elements)*2)+2

To create a final footer like:  <SHIPMENTSUMMARY elementcount=## />

Hereien lies the problem.  A simple counter I could increment (in ANY programming language) would make quick work of this problem.  But is XSLT I'm not seeing a way to solve the same problem.  I'm hoping someone will recognize the opertunity to use parent:sibling or something grouping by shipment id's to get correct counts.  Otherwise I have to scrap and start over.

Thanks.  An instant "A" to anyone that even sends me along the correct path.

Robert
0
Comment
Question by:crw030
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 2
  • 2
  • +1
15 Comments
 
LVL 9

Expert Comment

by:sparkplug
ID: 8026930
Hi,

Just to make sure I've understood you correctly before I begin:

If you start with this XML

<SHIPMENTS>
     <PACKAGE id="1" shipment="A" />
     <PACKAGE id="2" shipment="A" />
     <PACKAGE id="3" shipment="A" />
     <PACKAGE id="4" shipment="B" />
     <PACKAGE id="5" shipment="C" />
     <PACKAGE id="6" shipment="C" />
</SHIPMENTS>

you want to produce this output

<SHIPMENTS>
     <SHIPMENT name="A" packagecount="3">
          <PACKAGE id="1" />
          <PACKAGE id="2" />
          <PACKAGE id="3" />
     </SHIPMENT>
     <SHIPMENT name="B" packagecount="1">
          <PACKAGE id="4" />
     </SHIPMENT>
     <SHIPMENT name="C" packagecount="2">
          <PACKAGE id="5" />
          <PACKAGE id="6" />
     </SHIPMENT>
     <SHIPMENTSUMMARY elementcount="15" />
</SHIPMENTS>

Is that right?

>S'Plug<
0
 
LVL 1

Author Comment

by:crw030
ID: 8027024
spark,

Close.  However the starting XML is not so well shaped it is flat (more like you get from a FOR XML RAW statement on SQL Server than FOR XML EXPLICIT).  Currently I am obtaining a recordset from my SQL Server 7.0 server.  Then iterating through the recordset to build the
<PACKAGE id=1 shipment=A>
<PACKAGE id=2 shipment=A>
<PACKAGE id=3 shipment=A>
<PACKAGE id=4 shipment=B>
<PACKAGE id=5 shipment=C>
<PACKAGE id=6 shipment=C>
formatted XML string.  Note I dont have the (handy) parent <SHIPMENT> elements in my XML.  I'm currently working on creating more in that format (in case this question doesnt pan out).  I'd be done already if I was creating the XML from SQL Server 2000 using FOR XML EXPLICIT to define exactly the format I require.   :)

Each time my stylesheet encounters an outer SHIPMENT element it needs to create a couple specifically formatted blocks of text (1 for Address Info, 1 for Shipment info (like package qty etc), then for each package in the shipment (every shipment has at least 1) it needs to create another formatted text block (containing package details like indiv pkg weight).

Maybe a couple quick examples will help:

Shipment Q consisting of 3 packages should produce:
   1 Shipment Block, 1 Address block, 3 Package Detail Blocks.  As such it would contribute 5 blocks to my counter.

whereas Shipment R consisting of a single package should produce:
   1 Shipment Block, 1 Address block, 1 package detail block for 3 blocks addl.


Does that help?  With XSLT I've found creating the blocks and sub-blocks is really easy (template calls make quick work of it), but I cant keep track of how many I've created, so that once I'm all done I have a count.
0
 
LVL 9

Expert Comment

by:sparkplug
ID: 8027392
Sorry Robert, but

<PACKAGE id=1 shipment=A>
<PACKAGE id=2 shipment=A>
<PACKAGE id=3 shipment=A>
<PACKAGE id=4 shipment=B>
<PACKAGE id=5 shipment=C>
<PACKAGE id=6 shipment=C>

is not XML, there is no root tag and the attributes are not quoted, and as such can not be transformed using XSL. If you are building this from the recordset then maybe you could build it as XML?

Basically we just need an example of the input XML you are starting with and an example of the intending output.

Is the intending output I described above correct?

We will then have possibly have enough information work out the counting problem, although I think this is probably something which would be better done in SQL rather than XSL

It also might help if you could post the XSL you have worked on so far.

>S'Plug<

0
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 
LVL 1

Author Comment

by:crw030
ID: 8027548
Alright.  (For space reasons I trimmed it down a bit..but the basics should become clear)

test.xml
=====================
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="../xslt/0100.xsl"?>
<ROOT>
      <SHIPMENT CARRIER="UPS">
            <PACKAGERECORD PickupDate="2003.02.23"
                                    ShipperAccountNumber="XXX111"
                                    BookNumber="1111"
                                    PageNumber="1"
                                    ShipmentNumber="1ZXXX1110110000000"
                                    ShipmentPackageCount="5"
                                    ShipmentTotalWeight="42"
                                    PackageTrackingNumber="1ZXXX1110110000000"
                                    RecordType="0100"
                                    VersionNumber="0200"
                                    ConsigneeUPSAcctNumber=""
                                    ConsigneeCompanyName="FLORIDA TWO WAY SERVICE"
                                    ConsigneeAttention=""
                                    ConsigneeAddress1="2700 DAVIE RD"
                                    ConsigneeAddress2=""
                                    ConsigneeAddress3=""
                                    ConsigneeCity="DAVIE"
                                    ConsigneeStateProv="FL"
                                    ConsigneePostalCode="33314"
                                    ConsigneePhone=""
                                    ShipmentChgType="PRE"
                                    CWTCode="0"
                                    UPSServiceType="01"
                                    PackagingType="02"
                                    DeliveryZone=""
                                    PackageActualWeight="10"
                        </PACKAGERECORD>
            <PACKAGERECORD PickupDate="2003.02.23"
                                    ShipperAccountNumber="XXX111"
                                    BookNumber="1111"
                                    PageNumber="1"
                                    ShipmentNumber="1ZXXX1110110000000"
                                    ShipmentPackageCount="5"
                                    ShipmentTotalWeight="42"
                                    PackageTrackingNumber="1ZXXX1110110000001"
                                    RecordType="0100"
                                    VersionNumber="0200"
                                    ConsigneeUPSAcctNumber=""
                                    ConsigneeCompanyName="FLORIDA TWO WAY SERVICE"
                                    ConsigneeAttention=""
                                    ConsigneeAddress1="2700 DAVIE RD"
                                    ConsigneeAddress2=""
                                    ConsigneeAddress3=""
                                    ConsigneeCity="DAVIE"
                                    ConsigneeStateProv="FL"
                                    ConsigneePostalCode="33314"
                                    ConsigneePhone=""
                                    ShipmentChgType="PRE"
                                    CWTCode="0"
                                    UPSServiceType="01"
                                    PackagingType="02"
                                    DeliveryZone=""
                                    PackageActualWeight="10"
                        </PACKAGERECORD>
            <PACKAGERECORD PickupDate="2003.02.23"
                                    ShipperAccountNumber="XXX111"
                                    BookNumber="1111"
                                    PageNumber="1"
                                    ShipmentNumber="1ZXXX1110110000000"
                                    ShipmentPackageCount="5"
                                    ShipmentTotalWeight="42"
                                    PackageTrackingNumber="1ZXXX1110110000002"
                                    RecordType="0100"
                                    VersionNumber="0200"
                                    ConsigneeUPSAcctNumber=""
                                    ConsigneeCompanyName="FLORIDA TWO WAY SERVICE"
                                    ConsigneeAttention=""
                                    ConsigneeAddress1="2700 DAVIE RD"
                                    ConsigneeAddress2=""
                                    ConsigneeAddress3=""
                                    ConsigneeCity="DAVIE"
                                    ConsigneeStateProv="FL"
                                    ConsigneePostalCode="33314"
                                    ConsigneePhone=""
                                    ShipmentChgType="PRE"
                                    CWTCode="0"
                                    UPSServiceType="01"
                                    PackagingType="02"
                                    DeliveryZone=""
                                    PackageActualWeight="10"
                        </PACKAGERECORD>
            <PACKAGERECORD PickupDate="2003.02.23"
                                    ShipperAccountNumber="XXX111"
                                    BookNumber="1111"
                                    PageNumber="1"
                                    ShipmentNumber="1ZXXX1110110000000"
                                    ShipmentPackageCount="5"
                                    ShipmentTotalWeight="42"
                                    PackageTrackingNumber="1ZXXX1110110000004"
                                    RecordType="0100"
                                    VersionNumber="0200"
                                    ConsigneeUPSAcctNumber=""
                                    ConsigneeCompanyName="FLORIDA TWO WAY SERVICE"
                                    ConsigneeAttention=""
                                    ConsigneeAddress1="2700 DAVIE RD"
                                    ConsigneeAddress2=""
                                    ConsigneeAddress3=""
                                    ConsigneeCity="DAVIE"
                                    ConsigneeStateProv="FL"
                                    ConsigneePostalCode="33314"
                                    ConsigneePhone=""
                                    ShipmentChgType="PRE"
                                    CWTCode="0"
                                    UPSServiceType="01"
                                    PackagingType="02"
                                    DeliveryZone=""
                                    PackageActualWeight="10"
                        </PACKAGERECORD>
            <PACKAGERECORD PickupDate="2003.02.23"
                                    ShipperAccountNumber="XXX111"
                                    BookNumber="1111"
                                    PageNumber="1"
                                    ShipmentNumber="1ZXXX1110110000000"
                                    ShipmentPackageCount="5"
                                    ShipmentTotalWeight="42"
                                    PackageTrackingNumber="1ZXXX1110110000005"
                                    RecordType="0100"
                                    VersionNumber="0200"
                                    ConsigneeUPSAcctNumber=""
                                    ConsigneeCompanyName="FLORIDA TWO WAY SERVICE"
                                    ConsigneeAttention=""
                                    ConsigneeAddress1="2700 DAVIE RD"
                                    ConsigneeAddress2=""
                                    ConsigneeAddress3=""
                                    ConsigneeCity="DAVIE"
                                    ConsigneeStateProv="FL"
                                    ConsigneePostalCode="33314"
                                    ConsigneePhone=""
                                    ShipmentChgType="PRE"
                                    CWTCode="0"
                                    UPSServiceType="01"
                                    PackagingType="02"
                                    DeliveryZone=""
                                    PackageActualWeight="2"
                        </PACKAGERECORD>
            <PACKAGERECORD PickupDate="2003.02.23"
                                    ShipperAccountNumber="XXX111"
                                    BookNumber="1111"
                                    PageNumber="1"
                                    ShipmentNumber="1ZXXX1110120000000"
                                    ShipmentPackageCount="1"
                                    ShipmentTotalWeight="12"
                                    PackageTrackingNumber="1ZXXX1110120000000"
                                    ConsigneeCompanyName="BLAH TWO WAY SERVICE"
                                    ConsigneeAddress1="2700 MAIN ST"
                                    ConsigneeAddress2=""
                                    ConsigneeAddress3=""
                                    ConsigneeCity="BEVERLY HILLS"
                                    ConsigneeStateProv="CA"
                                    ConsigneePostalCode="90210"
                                    UPSServiceType="01"
                                    PackagingType="02"
                                    DeliveryZone=""
                                    PackageActualWeight="12"
                        </PACKAGERECORD>
            </SHIPMENT>
</ROOT>
0
 
LVL 1

Author Comment

by:crw030
ID: 8027559
And 0100.xsl  (sorry it's so big...kinda new to this.
==============


<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
<xsl:template match="/">
      <xsl:apply-templates select="/ROOT/SHIPMENT"></xsl:apply-templates>
</xsl:template>

<xsl:template match="/ROOT/SHIPMENT">
<xsl:apply-templates select="PACKAGERECORD" />
</xsl:template>

<xsl:template match="PACKAGERECORD">
  <xsl:if test="position()=1">
  <xsl:comment>VersionNumber length=4 value=0200</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@VersionNumber))=0">0200</xsl:when><xsl:otherwise><xsl:value-of select="normalize-space(@VersionNumber)" /></xsl:otherwise></xsl:choose>
  <xsl:comment>SourceTypeCode length=2 defaultvalue=93 (Host Manifest Upload)</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@SourceTypeCode))=0">93</xsl:when><xsl:otherwise><xsl:value-of select="normalize-space(@SourceTypeCode)" /></xsl:otherwise></xsl:choose>
  <xsl:comment>MailboxID length=24</xsl:comment><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="24"/></xsl:call-template>
  <xsl:comment>ClientSoftwareVersion length=10</xsl:comment><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="10"/></xsl:call-template>
  <xsl:comment>PickupDate format=YYYYMMDD</xsl:comment><xsl:apply-templates select="@PickupDate" />
  <xsl:comment>BookNumber length=12</xsl:comment><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="12-number(string-length(@BookNumber))"/></xsl:call-template><xsl:apply-templates select="@BookNumber" />
  <xsl:comment>PageNumber length=3</xsl:comment><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="3-number(string-length(@PageNumber))"/></xsl:call-template><xsl:apply-templates select="@PageNumber" />
  <xsl:comment>IncrementalPLDCode length=2</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@IncrementalPLDCode))=0">00</xsl:when><xsl:otherwise><xsl:value-of select="normalize-space(@IncrementalPLDCode)" /></xsl:otherwise></xsl:choose>
  <xsl:comment>SoftwareVendorCode length=3</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@SoftwareVendorCode))=0"><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="3"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="normalize-space(@SoftwareVendorCode)" /></xsl:otherwise></xsl:choose>
  <xsl:comment>NumShipperSeqsInFile length=9</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@NumShipperSeqsInFile))=0"><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="8"/></xsl:call-template>1</xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="8-number(string-length(normalize-space(@NumShipperSeqsInFile)))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@NumShipperSeqsInFile))" /></xsl:otherwise></xsl:choose>

  <xsl:comment>SegmentIdentifier length=3 Always *AA for Shipper Book block</xsl:comment><xsl:text>*AA</xsl:text>
  <xsl:comment>SenderShipperNumber length=10</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@ShipperAccountNumber))=0">!!!!!!!!!!</xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="10-number(string-length(@ShipperAccountNumber))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@ShipperAccountNumber))" /></xsl:otherwise></xsl:choose>
  <xsl:comment>ShipperCountry length=2 Always US</xsl:comment><xsl:text>US</xsl:text>
  <xsl:comment>ShipperEIN length=15 Shipper Exporter Identification Number</xsl:comment><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="15"/></xsl:call-template>
  <xsl:comment>CalculatedRatesInd length=1 SPACE</xsl:comment><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="1"/></xsl:call-template>
  <xsl:comment>BookNum length=7 Add leading zeroes as required. All zeroes fails.</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@BookNumber))=0">0000000</xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="7-number(string-length(normalize-space(@BookNumber)))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@BookNumber))" /></xsl:otherwise></xsl:choose>
  <xsl:comment>PageNumber length=3 Add leading zeroes as required.</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@PageNumber))=0">000</xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="3-number(string-length(normalize-space(@PageNumber)))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@PageNumber))" /></xsl:otherwise></xsl:choose>
  <xsl:comment>NumShipmentsInPage length=6 Add leading zeroes as required. Must equal the number of *BA segments that follow.</xsl:comment><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="6-number(string-length(string(number(last()))))"/></xsl:call-template><xsl:value-of select="string(number(last()))" />
</xsl:if>

 <xsl:if test="position()=1"><xsl:comment>Create one *BA block for each set of packages belonging to the same shipment</xsl:comment>
  <xsl:comment>SegmentIdentifier length=3 Always *BA for Shipment block</xsl:comment><xsl:text>*BA</xsl:text>
  <xsl:comment>ShipmentNumber length=35</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@ShipmentNumber))=0"><xsl:call-template name="FIXLENGTHEXCLAMATION"><xsl:with-param name="padCount" select="35"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(@ShipmentNumber))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@ShipmentNumber))" /></xsl:otherwise></xsl:choose>
  <xsl:comment>PackageCount length=5</xsl:comment><xsl:choose><xsl:when test="string-length(normalize-space(@ShipmentPackageCount))=0"><xsl:call-template name="FIXLENGTHEXCLAMATION"><xsl:with-param name="padCount" select="5"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="5-number(string-length(@ShipmentPackageCount))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@ShipmentPackageCount))" /></xsl:otherwise></xsl:choose>
  <xsl:comment>ShipmentActualWeight length=17 type=numeric desc=Sum of all package actual weights in shipment</xsl:comment>+<xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="16-number(string-length(@ShipmentTotalWeight))"/></xsl:call-template><xsl:value-of select="normalize-space(@ShipmentTotalWeight)" />
  <xsl:comment>AveragePkgWeightInd length=1 type=character desc=0-Actual package weights used</xsl:comment><xsl:text>0</xsl:text>
  <xsl:comment>ShipmentDimWeight length=17 type=real desc=(optional)15.1 formatted DimWeight for all packages in the shipment combined</xsl:comment>+<xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="16"/></xsl:call-template>
  <xsl:comment>UOMWeight length=3 type=character desc=LBS for pounds</xsl:comment><xsl:text>LBS</xsl:text>
  <xsl:comment>UPSServiceType length=2 type=Character desc=The service type used for all packages within the shipment</xsl:comment><xsl:choose><xsl:when test="string-length(@UPSServiceType)>=2"><xsl:value-of select="substring(@UPSServiceType,1,2)" /></xsl:when><xsl:otherwise><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="2-number(string-length(substring(@UPSServiceType,1,2)))"/></xsl:call-template><xsl:value-of select="normalize-space(substring(@UPSServiceType,1,2))" /></xsl:otherwise></xsl:choose>
  <xsl:comment>ShipmentChgType length=3 type=Character desc=PRE for prepaid shipments</xsl:comment><xsl:text>PRE</xsl:text>
  <xsl:comment>PaymentMediaTypeCode length=2 type=numeric desc=10-Invoice</xsl:comment><xsl:text>10</xsl:text>
  <xsl:comment>SenderName length=35 type=Character desc=Person at shipping location that sent the package</xsl:comment><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(@SenderName))"/></xsl:call-template><xsl:value-of select="normalize-space(normalize-space(@SenderName))" />
  <xsl:comment>DocInd length=1 type=Character desc=1-Document only Letter, 2-Non Document Letter, 3-Non document</xsl:comment><xsl:text>3</xsl:text>
  <xsl:comment>UOMDim length=2 type=Character desc=IN (Inches) CM</xsl:comment><xsl:text>IN</xsl:text>
  <xsl:comment>CurrencyCode length=3 type=Character desc=Us Dollars</xsl:comment><xsl:text>USD</xsl:text>
  <xsl:comment>NumPackagesInShipment length=6 type=Numeric desc=Total number of package details for the shipment.  Must match the quantity of *PA segments that follows</xsl:comment><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="6-number(string-length(@ShipmentPackageCount))"/></xsl:call-template><xsl:value-of select="normalize-space(@ShipmentPackageCount)" />
</xsl:if>
</xsl:template>

<xsl:template match="SHIPMENTRECORD">

</xsl:template>


<xsl:template match="@PickupDate">
<xsl:variable name="year" select="substring(.,1,4)" />
<xsl:variable name="month">
<xsl:value-of select="substring(.,6,2)" />
</xsl:variable>
<xsl:variable name="day" select="substring(.,9,2)" />
<xsl:value-of select="concat($year,$month,$day)" />
</xsl:template>



<xsl:template match="@ConsigneeUPSAcctNumber">
<xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="10-number(string-length(@ConsigneeUPSAcctNumber))"/></xsl:call-template><xsl:value-of select="." />
</xsl:template>

<xsl:template match="@ConsigneeCompanyName">
<xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(.))"/></xsl:call-template><xsl:value-of select="." />
</xsl:template>

<xsl:template match="@ConsigneeAttention">
<xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(.))"/></xsl:call-template><xsl:value-of select="." />
</xsl:template>

<xsl:template match="@ConsigneeAddress1">
<xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(@ConsigneeAddress1))"/></xsl:call-template><xsl:value-of select="." />
</xsl:template>

<xsl:template match="@ConsigneeAddress2">
<xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(@ConsigneeAddress2))"/></xsl:call-template><xsl:value-of select="." />
</xsl:template>

<xsl:template match="@ConsigneeAddress3">
<xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="35-number(string-length(@ConsigneeAddress3))"/></xsl:call-template><xsl:value-of select="." />
</xsl:template>



 <xsl:template name="FIXLENGTHEXCLAMATION">
     <xsl:param name="padCount" select="0"/>!<xsl:if  test="$padCount&gt;1"><xsl:call-template name="FIXLENGTHEXCLAMATION"><xsl:with-param name="padCount" select="number($padCount) - 1"/></xsl:call-template></xsl:if>
 </xsl:template>
 <xsl:template name="FIXLENGTH0">
     <xsl:param name="padCount" select="0"/>0<xsl:if  test="$padCount&gt;1"><xsl:call-template name="FIXLENGTH0"><xsl:with-param name="padCount" select="number($padCount) - 1"/></xsl:call-template></xsl:if>
 </xsl:template>
  <xsl:template name="FIXLENGTH">
     <xsl:param name="padCount" select="0"/>.<xsl:if  test="$padCount&gt;1"><xsl:call-template name="FIXLENGTH"><xsl:with-param name="padCount" select="number($padCount) - 1"/></xsl:call-template></xsl:if>
 </xsl:template>

</xsl:stylesheet>


0
 
LVL 1

Author Comment

by:crw030
ID: 8027636
Anyway.  The basic steps I'm already doing are:
If "position()=1" Then create:
   1. HEADER BLOCK
   2. *AA SEGMENT (which doesnt count towards the segment count)
   3. *BA SEGMENT for the first shipment.  A shipment is a collection of 1 or more packages to the same address.  Still working on how to identify the next shipment (since my XML is not in the form <SHIPMENT><PACKAGE /><PACKAGE /></SHIPMENT>.

Next I need to create *CA SEGMENT for each shipment (to hold the Address Info), followed by a *PA SEGMENT for each package.  Finally I need to Create a *SA SEGMENT (basically a file footer) that simply presents a count of all the *BA segments+*CA segments+*PA segments+*SA segment(1).


I'm half done....then I realized I was headed towards problems with the count.  I'm leaning more and more towards SQL, just that involves moving the DB to our SQL2000 box, and recompiling the apps that tie into it.  Maybe its for the best.  Honestly what would you recommend, am I trying to put a SQUARE bolt in a round hole?
0
 
LVL 1

Author Comment

by:crw030
ID: 8027958
Just in case it helps,  If I can get my XML in the form you mentioned in your first response, does it make the solution easier?  Maybe I can reformat my XML through code if it simplifies the problem.

Robert
0
 
LVL 1

Author Comment

by:crw030
ID: 8028407
I've worked up a more pronounced tree structure for my XML
like this.  I think this will work better with my templates, but does it help with the counting problem?

<ROOT>
   <BOOKPAGEBREAK attrib="" attrib2="" attrib3="">
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
   </BOOKPAGEBREAK>
</ROOT>

Haven't finished modifying the stylesheet, and I didn't include any data (just my sample data is like 10K)...don't want to clog up the discussion anymore.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8032755
>> I'm leaning more and more towards SQL...
My 2 cents: I would use SQL every time.  My main project at work outputs the same data into SQL tables and into XML.  Our customers pay a large premium to get the XML (I think some of them heard the term at a cocktail party or something) but then they struggle for months doing things that take 15 minutes with a good procedural language and simple, standard recordset access.

IMHO, XML should be used as transport container (especially when interfacing disparate systems), not as a working dataset container.  Well maybe that's a full nickel's worth :)

-- Dan
0
 
LVL 2

Accepted Solution

by:
FalconMaster earned 1200 total points
ID: 8033656
Hi crw,

I haven't had a chance to thoroughly look through your code, so this comment may be half baked, I apologize if it is.  I can't give you an answer, but maybe this will start you in the right direction.

It looks as if you are at least aware of using recursion, since xsl variables can only be assigned once.  That is good.

What you may want to consider is figuring out the counts using the "mode" parameter of the template.  This may allow you to utilize the whole xml dataset outside the specific node you are in for that specific purpose.

I am not sure I can explain it all that well here, but there are some good tutorials on http://www.zvon.org 

Here is an overview of examples there
http://www.zvon.org/xxl/XSLTreference/OutputOverview/xslt_apply-templates_mode_frame.html

Also, I noticed in some of your templates you do a
<call-template .../></call-template>

Note: when you put the / at the end of a tag, it closes that tag, and you do not need to then also put a </...> tag after it if you do this.  I don't know if that might be causing any of your problems.

Anyway, I hope this is helpful to you.

bye for now


0
 
LVL 1

Author Comment

by:crw030
ID: 8033757
Dan.
   Maybe I should clarify when I say move things to SQL what I'm talking about is from SQL7 to SQL2000 so I can use the FOR XML EXPLICIT to create an XML string (not a recordset).  More and more for slow changing data (like pulldowns etc) we're moving away from recordset based item population to XML item population.  Web servers are very good at serving the files to make this work, and a million pages per week using recordsets was killing our (low end) back-end database server.  Although I do see your point with solving a problem using the direct (simple+fast) recordset methods.  (We do that everyday....then we move stuff toward flat XML on the web servers where it makes sense)
  Either way nothing really beats the procedural+SQL DB approach to solve problems rapidly.  Thanks for your input.

Falcon.
I'm pretty sure the <call template /></call-template> isnt messing me up, but I'll fix anyway since it's wrong.  Funny thing is .NET creates the closing one automatically....grrr.  I prefer the "shorthand" where appropriate...but then I have to go in and delete all the closing tags. (wonder if I can turn that off)  Anyway I'll check out the examples via the links provided.

0
 
LVL 1

Author Comment

by:crw030
ID: 8066465
I've worked up a more pronounced tree structure for my XML
like this.  I think this will work better with my templates, but does it help with the counting problem?

<ROOT>
   <BOOKPAGEBREAK attrib="" attrib2="" attrib3="">
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
       <SHIPMENT sattrib1="" sattrib2="">
            <PACKAGERECORD lotsofattribs="" />
       </SHIPMENT>
   </BOOKPAGEBREAK>
</ROOT>

Haven't finished modifying the stylesheet, and I didn't include any data (just my sample data is like 10K)...don't want to clog up the discussion anymore.
0
 
LVL 1

Author Comment

by:crw030
ID: 8114719
All.

Since I've already pretty much solved my own problem, I'd be happy to give the points to one of you.

Maybe as part of the deal you can help me solve a (smaller) different problem.

Given a composite value like :  83A3R763991100100192
   *Note (in case it's relevant) this value is a combination of several XML element/attribute values...so if I apply-templates can I do it using these multiple values.

I need to do the following.

   1.  Replace Alpha characters with a lookup value that is numeric.  (Example A, K, U would be 2.  H,R is 9 etc)
   2.  Sum all the ODD location numbers (1st digit is position 1)
   3.  Add (to the previous Sum), 2X the sum of all the EVEN digits.

  I think some type of recursion would address this, however can I roll a sum "down the line" for use by the next iteration, and how can I keep track of whether I'm in an even or ODD position?


Also please indicate if you feel addl points are in order.
This will be it....300 points to the winner sometime tomorrow either way.
0
 
LVL 1

Author Comment

by:crw030
ID: 8125231
I'm giving the points to FalconMaster.  However for anyone who is interested in helping to work through the other problem I described...goes a 150 points (if it works).

I felt FalconMaster (although unable to provide an answer) was able to lead me towards some additional reading that will certainly be helpful in the future.
0
 
LVL 2

Expert Comment

by:FalconMaster
ID: 8126694
Hmm,

Thank you, I appreciate that.

Someday (hopefully), I will actually find time to actually answer some of these questions.  

But I am glad, at least, that my comment helped you out.
0

Featured Post

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question