My XML input looks like:
<?xml version="1.0" ?>
<input>
<record>
<name>James Smith</name>
<country>United Kingdom</country>
<opt>
good social skills,
<qualification>MSc</qualification>,
10 years of experience
</opt>
<section>1B</section>
</record>
<record>
<name>Rafael Pérez</name>
<country>Spain</country>
<section>2A</section>
</record>
<record>
<name>Marie-Claire Legrand</name>
<country>France</country>
<opt>
clear voice,
<qualification>MBA</qualification>,
3 years of experience
</opt>
<section>1B</section>
</record>
</input>
I want to output the text nodes under the <opt>
tag between parentheses, removing the starting and ending spaces and new lines around the contents of its children. This would be very easy if I had only a text child applying the function normalise-space()
to it, but this function cannot be applied to a set of nodes.
A MWE of my code looks as follows:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="utf-8"/>
<xsl:template match="input">
<xsl:text>------------------------------------------
</xsl:text>
<xsl:for-each select="record">
<xsl:apply-templates
select="node()[not(self::text()[not(normalize-space())])]"/>
<xsl:text>
------------------------------------------
</xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="qualification">
<xsl:choose>
<xsl:when test=". = 'MBA'">Master in Business Administration</xsl:when>
<xsl:when test=". = 'MSc'">Master in Sciences</xsl:when>
<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="name|country">
<xsl:value-of select="."/>
<xsl:text>, </xsl:text>
</xsl:template>
<xsl:template match="section">
<xsl:text>Section: </xsl:text>
<xsl:value-of select="."/>
<xsl:text>.</xsl:text>
</xsl:template>
<xsl:template match="opt">
<xsl:text>(</xsl:text>
<xsl:apply-templates/>
<xsl:text>), </xsl:text>
</xsl:template>
</xsl:stylesheet>
but gives me a wrong output, having spaces inside of the parentheses, as below:
------------------------------------------
James Smith, United Kingdom, (
good social skills,
Master in Sciences,
10 years of experience
), Section: 1B.
------------------------------------------
Rafael Pérez, Spain, Section: 2A.
------------------------------------------
Marie-Claire Legrand, France, (
clear voice,
Master in Business Administration,
3 years of experience
), Section: 1B.
------------------------------------------
The output want is:
------------------------------------------
James Smith, United Kingdom, (good social skills,
Master in Sciences,
10 years of experience), Section: 1B.
------------------------------------------
Rafael Pérez, Spain, Section: 2A.
------------------------------------------
Marie-Claire Legrand, France, (clear voice,
Master in Business Administration,
3 years of experience), Section: 1B.
------------------------------------------
I understand I have to modify the template "opt"
, but I cannot find how.