 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 10th, 2016, 10:49 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If string Null then add spaces
Hi All
Thanks for your help in advance
Very new to XSLT. Don't laugh at my basic skills. I would like to check to see if there is any easy and efficient way of re-writing this.
Appreciate your help in advance
I am combining all fields into Rows for each record and trying to build fixed length row at the end to output to a flat file which will be done in SAP Integration tool. The file adapter is unable to handle multiple hierarchy in SAP. So i am playing with XSLT here.
When combing the fields, if the field value is null where i would be adding spaces. One example with available. But i have to apply this for every field in the XSLT and pass the field length as a variable for easy handling.
<xsl:template match="/">
<ns0:MT_VendorInvoiceDetails_SAMS_FLAT xmlns:ns0="urn:sil.com:api12:ecc:ap:VendorInvoices ">
<Record>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Record_Type"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Type_Identifier"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Org_Code"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Agency_Name"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/File_Name"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Creation_Date"/>
<xsl:choose>
<xsl:when test="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Filler1 !=null">
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Filler1 " />
</xsl:when>
<xsl:otherwise>
&n bsp; &nbs p; &n bsp; &nbs p; &n bsp;
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select=""/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/DPA_Schedule_Number"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/DPA_Type"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/DPA_Category"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Filler17"/>
</Record>
<xsl:for-each select="/ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/Schedule_Record">
<Record>
<xsl:value-of select="Record_Type"/>
<xsl:value-of select="Filler2"/>
<xsl:value-of select="Appropriation_No"/>
<xsl:value-of select="Fiscal_Year"/>
<xsl:value-of select="Beginning_Voucher_Number"/>
<xsl:value-of select="Ending_Voucher_Number"/>
<xsl:value-of select="Schedule_Amount"/>
<xsl:value-of select="Voucher_Count"/>
<xsl:value-of select="Processing_Type"/>
<xsl:value-of select="Filler3"/>
</Record>
<xsl:for-each select="./Voucher_Transaction_Record">
<Record>
<xsl:value-of select="Record_Type"/>
<xsl:value-of select="Appropriation_No"/>
<xsl:value-of select="Fiscal_Year"/>
<xsl:value-of select="Voucher_Number"/>
<xsl:value-of select="Schedule_Payment_Date"/>
<xsl:value-of select="Invoice_Number"/>
<xsl:value-of select="Invoice_Date"/>
<xsl:value-of select="TIN"/>
<xsl:value-of select="Proper_Billing_Date"/>
<xsl:value-of select="Filler4"/>
<xsl:value-of select="Voucher_Amount"/>
<xsl:value-of select="First_Expenditure_Object"/>
<xsl:value-of select="First_Expenditure_Amount"/>
<xsl:value-of select="Second_Expenditure_Object"/>
<xsl:value-of select="Second_Expenditure_Amount"/>
<xsl:value-of select="Third_Expenditure_Object"/>
<xsl:value-of select="Third_Expenditure_Amount"/>
<xsl:value-of select="Fourth_Expenditure_Object"/>
<xsl:value-of select="Fourth_Expenditure_Amount"/>
<xsl:value-of select="Fifth_Expenditure_Object"/>
<xsl:value-of select="Fifth_Expenditure_Amount"/>
<xsl:value-of select="Payee_Name1"/>
<xsl:value-of select="Filler5"/>
<xsl:value-of select="Payee_Name2"/>
<xsl:value-of select="Filler6"/>
<xsl:value-of select="Address"/>
<xsl:value-of select="Filler7"/>
<xsl:value-of select="City"/>
<xsl:value-of select="Filler8"/>
<xsl:value-of select="State"/>
<xsl:value-of select="Filler18"/>
<xsl:value-of select="Zip_Code"/>
<xsl:value-of select="Filler9"/>
<xsl:value-of select="First_Oblication_Number"/>
<xsl:value-of select="Filler10"/>
<xsl:value-of select="First_Obligation_Amount"/>
<xsl:value-of select="Second_Oblication_Number"/>
<xsl:value-of select="Filler11"/>
<xsl:value-of select="Second_Obligation_Amount"/>
<xsl:value-of select="Third_Oblication_Number"/>
<xsl:value-of select="Filler12"/>
<xsl:value-of select="Third_Obligation_Amount"/>
<xsl:value-of select="Filler13"/>
<xsl:value-of select="Direct_Deposit_Indicator"/>
<xsl:value-of select="Contact_Reference"/>
<xsl:value-of select="Filler14"/>
<xsl:value-of select="DirectDepositMultipleAccountNoIndicator"/>
<xsl:value-of select="Check_Category"/>
<xsl:value-of select="Remittance_Description"/>
<xsl:value-of select="Billing_Account_Number"/>
<xsl:value-of select="Credit_Memo_Number"/>
<xsl:value-of select="Credit_Memo_Amount"/>
<xsl:value-of select="Beginning_Date_of_Service"/>
<xsl:value-of select="Ending_Date_of_Service"/>
<xsl:value-of select="GAPP_Code"/>
<xsl:value-of select="PreAudit_Description"/>
<xsl:value-of select="Confidentiality_Indicator"/>
<xsl:value-of select="Filler15"/>
</Record>
</xsl:for-each>
</xsl:for-each>
<Record>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/TrailerRecord/Record_Type"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/TrailerRecord/Schedule_Record_Count"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/TrailerRecord/Schedule_Control_Total"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/TrailerRecord/Voucher_Record_Count"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/TrailerRecord/Voucher_Control_Total"/>
<xsl:value-of select="ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader/TrailerRecord/Filler16"/>
</Record>
</ns0:MT_VendorInvoiceDetails_SAMS_FLAT>
</xsl:template>
|
|

June 11th, 2016, 03:26 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You'll have to explain what you mean by "null" because there is no such concept in the XPath data model. Possible meanings:
- the element doesn't exist
- the element exists but has no (text or element) child nodes
- the element content consists entirely of whitespace
It's also useful to say whether you are using XSLT 1.0, 2.0, or 3.0, since the solutions may well vary.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

June 11th, 2016, 10:58 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I may need to consider below two items for my requirement
- the element doesn't exist
- the element exists but has no (text or element) child nodes
|
|

June 11th, 2016, 11:30 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
You can use
Code:
<xsl:when test="foo">...</xsl:when>
to check whether a foo element exists (as a child of the context node) and
Code:
<xsl:when test="foo[not(* | text())]">
to check that a foo element exists but does not have any element or text child nodes. Unless you want to allow comment nodes and processing instruction nodes you might simply want
Code:
<xsl:when test="foo[not(node())]">
which checks that there is a foo element with no child nodes at all.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

June 11th, 2016, 04:37 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
is there an easy way to add spaces other than multiple time?
|
|

June 12th, 2016, 12:34 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
finally wrote complete flat file output using the below XSLT. But the output is not in rows as expected, the text goes everywhere. Not sure this is my notepad or ai am doing something wrong
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:sil.com:api12:ecc:ap:VendorInvoices ">
<xsl:output method="text" indent="no"/>
<xsl:variable name="some_spaces"
select="' '"/>
<xsl:template match="/">
<xsl:apply-templates select="//ns0:MT_VendorInvoiceDetails_SAMS/VendorInvoiceHeader"/>
</xsl:template>
<xsl:template match="VendorInvoiceHeader">
<xsl:apply-templates mode="format" select="./Record_Type">
<xsl:with-param name="width" select="number(2-1)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Type_Identifier">
<xsl:with-param name="width" select="number(8-3)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Org_Code">
<xsl:with-param name="width" select="number(11-9)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Agency_Name">
<xsl:with-param name="width" select="number(41-12)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="File_Name">
<xsl:with-param name="width" select="number(53-42)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Creation_Date">
<xsl:with-param name="width" select="number(59-54)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="DPA_Schedule_Number">
<xsl:with-param name="width" select="number(65-60)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="DPA_Type">
<xsl:with-param name="width" select="number(75-66)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="DPA_Category">
<xsl:with-param name="width" select="number(85-76)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler17">
<xsl:with-param name="width" select="number(900-76)"/>
</xsl:apply-templates>
<xsl:text>
</xsl:text>
<xsl:for-each select="Schedule_Record">10
<xsl:apply-templates mode="format" select="Filler2">
<xsl:with-param name="width" select="number(8-3)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Appropriation_No">
<xsl:with-param name="width" select="number(24-9)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fiscal_Year">
<xsl:with-param name="width" select="number(26-25)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Beginning_Voucher_Number">
<xsl:with-param name="width" select="number(34-27)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Ending_Voucher_Number">
<xsl:with-param name="width" select="number(42-35)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Schedule_Amount">
<xsl:with-param name="width" select="number(54-43)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Voucher_Count">
<xsl:with-param name="width" select="number(58-55)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Processing_Type">
<xsl:with-param name="width" select="number(59-59)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler3">
<xsl:with-param name="width" select="number(900-60)"/>
</xsl:apply-templates>
<xsl:for-each select="Voucher_Transaction_Record">11
<xsl:apply-templates mode="format" select="Appropriation_No">
<xsl:with-param name="width" select="number(18-3)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fiscal_Year">
<xsl:with-param name="width" select="number(20-19)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Voucher_Number">
<xsl:with-param name="width" select="number(28-21)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Schedule_Payment_Date">
<xsl:with-param name="width" select="number(34-29)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Invoice_Number">
<xsl:with-param name="width" select="number(44-35)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Invoice_Date">
<xsl:with-param name="width" select="number(50-45)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="TIN">
<xsl:with-param name="width" select="number(59-51)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Proper_Billing_Date">
<xsl:with-param name="width" select="number(65-60)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler4">
<xsl:with-param name="width" select="number(66-66)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Voucher_Amount">
<xsl:with-param name="width" select="number(76-67)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fifth_Expenditure_Object">
<xsl:with-param name="width" select="number(80-77)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fifth_Expenditure_Amount">
<xsl:with-param name="width" select="number(90-81)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Second_Expenditure_Object">
<xsl:with-param name="width" select="number(94-91)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Second_Expenditure_Amount">
<xsl:with-param name="width" select="number(104-95)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Third_Expenditure_Object">
<xsl:with-param name="width" select="number(108-105)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Third_Expenditure_Amount">
<xsl:with-param name="width" select="number(118-109)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fourth_Expenditure_Object">
<xsl:with-param name="width" select="number(122-119)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fourth_Expenditure_Amount">
<xsl:with-param name="width" select="number(132-123)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fifth_Expenditure_Object">
<xsl:with-param name="width" select="number(136-133)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Fifth_Expenditure_Amount">
<xsl:with-param name="width" select="number(146-137)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Payee_Name1">
<xsl:with-param name="width" select="number(176-147)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler5">
<xsl:with-param name="width" select="number(178-177)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Payee_Name2">
<xsl:with-param name="width" select="number(208-179)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler6">
<xsl:with-param name="width" select="number(210-209)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Address">
<xsl:with-param name="width" select="number(240-211)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler7">
<xsl:with-param name="width" select="number(242-241)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="City">
<xsl:with-param name="width" select="number(260-243)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler8">
<xsl:with-param name="width" select="number(262-261)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="State">
<xsl:with-param name="width" select="number(265-265)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler18">
<xsl:with-param name="width" select="number(274-265)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Zip_Code">
<xsl:with-param name="width" select="number(275-275)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler9">
<xsl:with-param name="width" select="number(285-276)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="First_Obligation_Number">
<xsl:with-param name="width" select="number(286-286)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler10">
<xsl:with-param name="width" select="number(296-287)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="First_Obligation_Amount">
<xsl:with-param name="width" select="number(306-297)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Second_Obligation_Number">
<xsl:with-param name="width" select="number(307-307)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler11">
<xsl:with-param name="width" select="number(317-308)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Second_Obligation_Amount">
<xsl:with-param name="width" select="number(327-318)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Third_Obligation_Number">
<xsl:with-param name="width" select="number(328-328)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler12">
<xsl:with-param name="width" select="number(338-329)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Third_Obligation_Amount">
<xsl:with-param name="width" select="number(347-339)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler13">
<xsl:with-param name="width" select="number(348-348)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Direct_Deposit_Indicator">
<xsl:with-param name="width" select="number(358-349)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Contract_Reference">
<xsl:with-param name="width" select="number(373-359)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler14">
<xsl:with-param name="width" select="number(376-374)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="DirectDepositMultipleAccountNoIndicator">
<xsl:with-param name="width" select="number(378-377)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Check_Category">
<xsl:with-param name="width" select="number(438-379)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Remittance_Description">
<xsl:with-param name="width" select="number(484-469)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Billing_Account_Number">
<xsl:with-param name="width" select="number(496-485)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Credit_Memo_Number">
<xsl:with-param name="width" select="number(506-497)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Credit_Memo_Amount">
<xsl:with-param name="width" select="number(514-507)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Beginning_Date_of_Service">
<xsl:with-param name="width" select="number(522-515)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="GAAP_Code">
<xsl:with-param name="width" select="number(526-523)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="PreAudit_Description">
<xsl:with-param name="width" select="number(886-527)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Confidentiality_Indicator">
<xsl:with-param name="width" select="number(887-887)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler15">
<xsl:with-param name="width" select="number(900-888)"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:for-each>99
<xsl:apply-templates mode="format" select="./TrailerRecord/Schedule_Record_Count">
<xsl:with-param name="width" select="number(6-3)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="./TrailerRecord/Voucher_Record_Count">
<xsl:with-param name="width" select="number(11-7)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="./TrailerRecord/Schedule_Control_Total">
<xsl:with-param name="width" select="number(23-12)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="./TrailerRecord/Voucher_Control_Total">
<xsl:with-param name="width" select="number(35-24)"/>
</xsl:apply-templates>
<xsl:apply-templates mode="format" select="Filler16">
<xsl:with-param name="width" select="number(900-36)"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="node()" mode="format">
<xsl:param name="width"/>
<xsl:value-of select="substring(concat(text(),$some_spaces ), 1, $width+1)"/>
</xsl:template>
<xsl:template match="node()" mode="format_date">
<xsl:param name="width"/>
<xsl:value-of select="substring(concat(translate(text(),'/',''),$some_spaces ), 1, $width+1)"/>
</xsl:template>
</xsl:stylesheet>
|
|

June 12th, 2016, 04:50 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
In XSLT 2.0 you can do
Code:
string-join(for $i in 1 to $N return ' ', '')
In XSLT 1.0 you can do
Code:
substring($spaces, 1, $N)
where $spaces is a variable containing more spaces than you will ever need.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

June 12th, 2016, 12:01 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
where does the snippet of code go into this template.
<xsl:template match="node()" mode="format">
<xsl:param name="width"/>
<xsl:value-of select="substring(concat(text(),$some_spaces ), 1, $width+1)"/>
</xsl:template>
<xsl:template match="node()" mode="format_date">
<xsl:param name="width"/>
<xsl:value-of select="substring(concat(translate(text(),'/',''),$some_spaces ), 1, $width+1)"/>
</xsl:template>
|
|

June 12th, 2016, 01:44 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
The first template takes the text content of the current node (text()), appends some spaces, and then returns the first $width characters of the result.
The second template does something very similar except that it uses translate() to remove "/" characters first.
Not sure which part of that you had difficulty understanding; if I knew where your difficulty was then I could explain that bit more carefully.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
 |