Re: [xsl] How would I go about changing my single quotes to double quotes in my XML output line ?

Subject: Re: [xsl] How would I go about changing my single quotes to double quotes in my XML output line ?
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 Nov 2014 22:14:10 -0000
Graydon already answered you, but you might  consider some other options as
well:

1) change all double to single and all single to double-quotes
2) use a variable for the quote value (XSLT 1.0 and 2.0)
3) use a partial function application for the quoting fn:concat (XSLT 3.0)

Ex. of 1:
<xsl:value-of select='concat("""",../external_id[1],""""),   ....' />

Ex. of 2:
<xsl:variable name="quot" select=' """" ' />
<xsl:value-of select='concat($quot ,../external_id[1], $quot),   ....' />

Ex. of 3:
<xsl:variable name="quotate" select='concat("""", ?, """")' />
<xsl:value-of select='$quotate(,../external_id[1]),   ....' />

If you can use XSLT 3.0, the third option is probably easiest and removes some
of the clutter caused by all the fn:concat invocations. But you can reach the
same in XSLT 2.0 with xsl:function, it is just a bit more work.

In addition, instead of creating such big xsl:value-of statements, consider
splitting it up in smaller ones, using apply-templates on the nodes, or place
them in a sequence of items. Or, in XSLT 3.0, using Content Value Templates.
Anything that makes such large xsl:value-of statements easier to read is
probably a good thing for maintainability of the code.

Cheers,
Abel


From: Catherine Wilbur cwilbur@xxxxxxxxxxx
[mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, November 20, 2014 11:06 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] How would I go about changing my single quotes to double quotes
in my XML output line ?

Have following code in XSL stylesheet

Have string fields I surround by single quotes.  How would I change the single
quote to a double quote without getting a syntax error in the <xsl:value-of
select=.  Reason I am asking is because some of my string fields might have a
single quote embedded so I want to surround my string fields by double quotes.
With the logic below it causes a syntax error with the <xsl:value-of select="
field sytax.

Anyone have any ideas?

                 <!--
                              ===============================================
=============================================================================
====
                                Output the CSV comma delimited file with
fields in the following order:
                                  Seq#, UserId, Batch#, Vendor#, GLAcct,
Invoice#, InvoiceDate, GLDate, Currency, ExchgRate, TotInvoiceAmnt,
InvoiceLineAmnt, Attachment, PaymentTerms, Remark

                                  Remark is a combination of the unique
identifier (16 chars) plus the first 14 characters of the vendor code

                               "&#xa" is a line feed  (this is one we need to
use to generate new line)
                               "&#xD" is a carriage return

                                Note:  Amount fields and exchange rate fields
must be written out as implied decimal fields
                                =============================================
=============================================================================
======
                                -->
                              <xsl:value-of select="position(),
                                'LIBPROD',
                                local:sort-key($InvoiceCurrency,$InvoicePOLin
eOwner),
                                $Derived_FISVendorNo,
                                concat('''',../external_id[1],''''),
                                concat('''',$inv/invoice_number[1],''''),
                                concat(substring($InvoiceDateValue,5,4),subst
ring($InvoiceDateValue,1,2),substring($InvoiceDateValue,3,2)),
                                $Derived_GLDateValue,
                                $inv/invoice_amount[1]/currency[1],
                                $Derived_ExchgRate,
                                $Derived_InvoiceAmnt,
                                $Derived_InvoiceLineFundAmnt,
                                $Derived_PaymentAttachment,
                                $Derived_PaymentTerms
,
                                concat('''',$inv/unique_identifier[1],substri
ng($inv/vendor_code[1],1,14),'''')" separator=","/>
                              <xsl:text>&#xa;</xsl:text>

_____________________________________________________________________
Catherine Wilbur
  (E) cwilbur@xxxxxxxxxxx
www.uwindsor.ca/its
XSL-List info and archive
EasyUnsubscribe (by email)

Current Thread