A puro XPath 2.0 espressione:
for $b in /*/book
return
concat(escape-html-uri(string-join(($b/@isbn,
$b/title,
$b/description
)
/normalize-space(),
",")
),
codepoints-to-string(10))
XSLT 2 - verifica base:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:sequence select=
"for $b in /*/book
return
concat(escape-html-uri(string-join(($b/@isbn,
$b/title,
$b/description
)
/normalize-space(),
',')
),
codepoints-to-string(10))"/>
</xsl:template>
</xsl:stylesheet>
Quando questa trasformazione è applicato sul documento XML fornito (corretta dal suo malformazioni):
<books>
<book isbn="1590593049">
<title>Extending Flash MX 2004</title>
<description>
Using javascript alongwith actionscript 3.0 and mxml.</description>
</book>
<book isbn="0132149184">
<title>Java Software Solutions</title>
<description>
Complete book full of case studies on business solutions and design concepts while building mission critical
business applications.
</description>
</book>
</books>
The Wanted, risultato corretto è prodotta:
1590593049,Extending Flash MX 2004,Using javascript alongwith actionscript 3.0 and mxml.
0132149184,Java Software Solutions,Complete book full of case studies on business solutions and design concepts while building mission critical business applications.
Aggiornamento:
In un commento il PO ha richiesto che ogni virgola avvolgere in-testo di un preventivo e che (dopo di che) ogni citazione viene sostituita da due virgolette e, infine, se il risultato contiene una citazione, deve essere racchiuso tra virgolette (singole).
Qui è una pura espressione XPath 2.0 che produce questo:
for $b in /*/book,
$q in codepoints-to-string(34),
$NL in codepoints-to-string(10),
$isbn in normalize-space(replace($b/@isbn, ',', concat($q,',',$q))),
$t in normalize-space(replace($b/title, ',', concat($q,',',$q))),
$d in normalize-space(replace($b/description, ',', concat($q,',',$q))),
$res in
escape-html-uri(string-join(($isbn,$t,$d), ',')),
$res2 in replace($res, $q, concat($q,$q))
return
if(contains($res2, $q))
then concat($q, $res2, $q, $NL)
else concat($res2, $NL)
Quando questa espressione XPath viene valutata contro questo (ampliato con un nuovo test e minuscole) documento XML:
<books>
<book isbn="1590593049">
<title>Extending Flash MX 2004</title>
<description>
Using javascript alongwith actionscript 3.0 and mxml.</description>
</book>
<book isbn="0132149184">
<title>Java Software Solutions</title>
<description>
Complete book full of case studies on business solutions and design concepts while building mission critical
business applications.
</description>
</book>
<book isbn="XX1234567">
<title>Quotes and comma</title>
<description>
Hello, World from "Ms-Excel"
</description>
</book>
</books>
il ricercato, il risultato corretto è prodotto:
1590593049,Extending Flash MX 2004,Using javascript alongwith actionscript 3.0 and mxml.
0132149184,Java Software Solutions,Complete book full of case studies on business solutions and design concepts while building mission critical business applications.
"XX1234567,Quotes and comma,Hello"","" World from ""Ms-Excel"""
ma se fosse XPath 2 puro non interpreterebbe ' ' come interruzione di riga – BeniBela
@BeniBela, La tua domanda non è chiara - Ho aggiornato la mia risposta con un Trasformazione XSLT che utilizza la stessa espressione XPath. Nel caso in cui non si trattasse di un'espressione XPath legale, si sarebbe verificato un errore, ma la trasformazione funzionerà senza problemi –
Bene, se lo includi in XSLT non è più * puro * XPath. Quindi il parser XML sostituisce & # xa. Se esegui semplicemente * pure * XPath senza XSLT ottieni: '1590593049, Estensione di Flash MX 2004, Utilizzo di javascript con actionscript 3.0 e mxml. 0132149184, Soluzioni software Java, libro completo completo di casi studio su soluzioni aziendali e concetti di progettazione mentre si costruiscono applicazioni aziendali mission-critical. 'nell'esempio – BeniBela