0

Providing a namespace prefix in order to transform XML to XSLT has been broadly covered at SO. See e.g. XSLT Transform XML with Namespaces, XSLT with XML source that has a default namespace set to xmlns, and XSLT Transformating XML to XML. However, after countless hours of research and trial-and-error approach I can say that I failed to make it work.

Here's my XML file:

<?xml version="1.0" encoding="utf-8"?>
<library xmlns="http://void.net/library/1.0">
    <catalog>
        <cd id="c1">
            <singer id="s1">
                <name>Kate</name>
                <surname>Apple</surname>
            </singer>
        <title>Great CD</title>
        </cd>
        <cd id="c2">
            <singer id="s2">
                <name>Mary</name>
                <surname>Orange</surname>
            </singer>
        <title>Even better CD</title>
        </cd>
    </catalog>
</library>

This is what I've come up so far:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    xmlns:b="http://void.net/library/1.0"
    exclude-result-prefixes="b">
    <xsl:output method="text" indent="no" />

    <xsl:template match="/b:library">
        <xsl:text>singer,title
        </xsl:text>
        <xsl:for-each select="b:catalog/b:cd">
            <xsl:value-of select="concat(b:singer/b:name, ' ', b:singer/b:surname, ', ', b:title, '
')" />
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Here's example and error list

menteith
  • 596
  • 14
  • 51

1 Answers1

0

I fixed the typos in the stylesheet and came up with this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:b="http://void.net/library/1.0" exclude-result-prefixes="b">
    <xsl:output method="text" indent="no" />

    <xsl:template match="/b:library">
        <xsl:text>singer,title&#xa;</xsl:text>
        <xsl:for-each select="b:catalog/b:cd">
            <xsl:value-of select="concat(b:singer/b:name, ' ', b:singer/b:surname, ', ', b:title, '&#xa;')" />
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Output:

singer,title
Kate Apple, Great CD
Mary Orange, Even better CD

So everything seems to work as expected.

zx485
  • 28,498
  • 28
  • 50
  • 59