All,
I'm soliciting some validation of my approach to developing XSL for a
project I'm working on after receiving some very welcome help yesterday.
Questions:
1. In the XSL below, is it a reasonable approach to discard
"unwanted" text nodes with the template
<xsl:template match="frq:From | frq:HeaderDate | frq:HeaderTime
| frq:FaxNumber">
</xsl:template>?
* Is there a better way to do this?
* Must this be done element-by-element, or is there a
"shorthand" way of eliminating a set of sibling nodes via XPath
expression?
2. Given the inclusion of the namespace specifier
"xmlns:frq="http://www.fedex.com/schemas/freightRateQuotation" in the
XSL, must all references to nodes in that namespace always be preceded
with "frq:" wherever they are referenced (such as in xsl:template
match="..." statements)?
3. I'd like to "left align" the "To:" and "Email Address:" lines in
my output. Is there a defined set of output formatting rules in XSL
(which in particular defines how output lines are indented)? As
suggested yesterday by Michael Ludwig, I included an "<xsl:output
method="html" indent="yes"/>" line, but that doesn't seem to impact
other than the HTML syntax elements.
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tFreightRateQuotation
xmlns="http://www.fedex.com/schemas/freightRateQuotation">
<AccountInformation>
<CompanyName>Customer Company</CompanyName>
<Address1>123 Main Street</Address1>
<City>Anytown</City>
<State>CO</State>
<Postal>80134</Postal>
<Country>US</Country>
</AccountInformation>
<CommonData>
<To>John Customer</To>
<From>Fedex</From>
<HeaderDate>02/02/10</HeaderDate>
<HeaderTime>12:01:00</HeaderTime>
<FaxNumber>3031234567</FaxNumber>
<EmailAddress>[email protected]</EmailAddress>
</CommonData>
<RateQuote>
<QuoteNumber>1 12345678</QuoteNumber>
<OriginAddress>
<OriginCity>Salt Lake City</OriginCity>
<OriginState>UT</OriginState>
<OriginPostal>84106</OriginPostal>
<OriginCountry>US</OriginCountry>
</OriginAddress>
</RateQuote>
</tFreightRateQuotation>
XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:frq="http://www.fedex.com/schemas/freightRateQuotation"
exclude-result-prefixes="frq">
<xsl:output method="html" indent="yes"/>
<xsl:template match="frq:tFreightRateQuotation">
<html>
<body>
<!--Add a newline-->
<xsl:text>
</xsl:text>
<xsl:apply-templates select="frq:CommonData"/>
<!--Add a newline-->
<xsl:text>
</xsl:text>
</body>
</html>
</xsl:template>
<xsl:template match="frq:To">
<xsl:text> To: </xsl:text>
<xsl:value-of select="."/>
<!--Add a newline-->
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="frq:From | frq:HeaderDate | frq:HeaderTime |
frq:FaxNumber">
</xsl:template>
<xsl:template match="frq:EmailAddress">
<xsl:text> Email Address: </xsl:text>
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
Resulting Output:
<html>
<body>
To: John Customer
Email Address: [email protected]
</body>
</html>
Thanks in advance for your time and advice. It's been very encouraging.
Tim Hibbs
FedEx Services
350 Spectrum Loop
Colorado Springs, CO 80921
719-484-2131