Hi Don. Thanks for your response.
I'll provide it, but my ultimate goal is to make the main template which
outputs my field-value pairs as simple as possible. I need to set up a
bunch of variables in an include file beforehand so that a
non-programmer will be able to edit the XSLT (and create more XSLTs for
the same source XML) with ease.
---------
Sample Source XML. In this sample there is one borrower, whose values I
want to put in some variables such as $buyer, $buyerfname,
$buyerprimaryaddress, $buyerprimaryaddressline1, etc. HOWEVER, I also
want to set up variables for the cobuyer so the guy who comes behind me
can easily reference them w/o having to do any complicated XPath or XSLT
stuff.
This is greatly simplified of course.
<Borrowers>
<Borrower>
<NumOrder>1</NumOrder>
<FirstName>John</FirstName>
<MiddleName>Q</MiddleName>
<LastName>Public</LastName>
<HomePhone>1234567890</HomePhone>
<Addresses>
<BorrowerAddress>
<NumOrder>1</NumOrder>
<IsCurrent>true</IsCurrent>
<Type>GeneralDelivery</Type>
<StreetNumber>123</StreetNumber>
<StreetName>Main</StreetName>
<StreetPrefix />
<StreetSuffix>St.</StreetSuffix>
<ApartmentSuiteNumber>Apt 66</ApartmentSuiteNumber>
<PostOfficeBox />
<RuralRoute />
<MilitaryAPOFPO />
<City>Beaumont</City>
<CountyParish>Jefferson</CountyParish>
<State>TX</State>
<Zip>77706</Zip>
</BorrowerAddress>
</Addresses>
</Borrower>
</Borrowers>
---------
Sample Output:
<FieldValuePairs>
<FieldValuePair field="BuyerState" value="TX" />
<FieldValuePair field="BuyerFullNameStreetCityStateZipPhone"
value="Autos, Inc.
123 Lezmakadel Ln.
Jacksonville, MI
12345" />
</FieldValuePairs>
I *think* the 
 are carriage-return+linefeed sequences.
Chris Bordeman
-----Original Message-----
From: Don Smith [mailto:dsmith_lockesmith(_at_)yahoo(_dot_)com]
Sent: Friday, August 08, 2008 3:07 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Forgive the noob
Chris,
If you can provide an example of the source XML as well as an example of
what the target output should be, it would help.
Don
--- On Fri, 8/8/08, Bordeman, Chris
<Chris(_dot_)Bordeman(_at_)wolterskluwer(_dot_)com>
wrote:
From: Bordeman, Chris <Chris(_dot_)Bordeman(_at_)wolterskluwer(_dot_)com>
Subject: [xsl] Forgive the noob
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: Friday, August 8, 2008, 3:00 PM
Hi guys, doing my first XSLT and need a bit of help.
Basically, I'm transforming essentially a serialized object structure
into a list of field-value pair nodes.
There are a lot of complicated nodes I need to get at often, like the
first address node under the first customer so I wanted to set up a
bunch of variables and locate and and assign helper variables before I
get into the template proper, which is itself very simple.
I've written
some functions to help w/ this and a single named template called
"init"
I call up front to set up the variables.
The problem is when I assign to the variables inside my named
template, they don't keep their value. I'd just add this stuff to the
main template but I really need to split all this init stuff into an
include file or something so they can be reused in other xslts.
How can I make these variables visible where I need to use them?
Here's a bit of what I'm doing now:
<!-- declare global helper variables -->
<xsl:variable name="buyerfullname"
select="''"/>
<xsl:variable name="buyeraddress"
select="''"/>
<xsl:variable name="buyeraddress1"
select="''"/>
<xsl:variable name="buyercsz"
select="''"/>
<xsl:variable name="buyerhomephone"
select="''"/>
<xsl:variable name="buyerblock"
select="''"/>
<xsl:template name="init">
<xsl:variable name="buyer"
select="Contract/Borrowers/Borrower[NumOrder='1']"/>
<xsl:choose>
<xsl:when test="string($buyer) !=
''">
<xsl:variable name="buyerfullname"
select="fn:borrowerfullname($buyer)"/>
<xsl:variable name="buyeraddress"
select="$buyer/Addresses/BorrowerAddress[IsCurrent='true'
and
position()=1]"/>
<xsl:variable name="buyeraddress1"
select="fn:address1($buyeraddress)"/>
<xsl:variable name="buyercsz"
select="fn:csz($buyeraddress)"/>
<xsl:variable name="buyerhomephone"
select="$buyer/HomePhone/PhoneNumber"/>
<xsl:variable name="buyerblock"
select="string-join(($buyerfullname,$buyeraddress1,$buyercsz,$buyerhom
ep
hone),fn:crlf())"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- create helper variables -->
<xsl:call-template name="init"/>
<!-- Main Template, generates FieldValuePairs -->
<!-- ERRORS: I GET 'VARIABLE DOES NOT EXIST'
ERRORS -->
<xsl:template match="/">
<FieldValuePairs>
<FieldValuePair field="BuyerState">
ERROR ---> <xsl:attribute
name="value"><xsl:value-of
select="$buyeraddress/State"/></xsl:attribute>
</FieldValuePair>
<FieldValuePair
field="BuyerFullNameStreetCityStateZipPhone">
ERROR ---> <xsl:attribute
name="value"><xsl:value-of
select="$buyerblock"/></xsl:attribute>
</FieldValuePair>
</FieldValuePairs>
</xsl:template>
Thanks for any help!
Chris Bordeman
--~------------------------------------------------------------------
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--