I have the problem with xslt. How to exactly use template to build output like this? I get tired already a long time with this, and it is problematic to use a tag xmlns
<?xml version="1.0" encoding="utf-8"?>
<books xmlns="http://example.net/books/1.0" xmlns:a="http://example.net/author/1.0">
<book>
<a:author>
<a:name>John</a:name>
<a:surname>Applesed</a:surname>
</a:author>
<title>Missing opportunity</title>
</book>
<book>
<a:author>
<a:name>Paul</a:name>
<a:surname>Morgan</a:surname>
</a:author>
<title>Test Book</title>
</book>
</books>
So far I was able to do something like this:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b="http://example.net/library/1.0" >
<xsl:template match="/">
<books>
<xsl:for-each select="b:library/b:books/b:book">
<book>
<author>
<name>
<xsl:value-of select="../../b:authors/b:author/b:name"/>
</name>
<surname>
<xsl:value-of select="../../b:authors/b:author/b:surname"/>
</surname>
</author>
<title>
<xsl:value-of select="b:title"/>
</title>
</book>
</xsl:for-each>
</books>
</xsl:template>
</xsl:stylesheet>
Starting file is: This file cannot be edited
<?xml version="1.0" encoding="utf-8"?>
<library xmlns="http://example.net/library/1.0">
<authors>
<author id="a1">
<name>John</name>
<surname>Applesed</surname>
<born>1979-11-11</born>
</author>
<author id="a2">
<name>Chris</name>
<surname>Pattern</surname>
<born>1965-12-12</born>
</author>
<author id="a3">
<name>Paulo</name>
<surname>Coelho</surname>
<born>1915-06-17</born>
</author>
<author id="a4">
<name>Paul</name>
<surname>Morgan</surname>
<born>1473-02-19</born>
<died>1543-05-24</died>
</author>
</authors>
<books>
<book id="b1" author-id="a1">
<title>Missing opportunity</title>
<published>1992</published>
<isbn>978-3-16-148410-0</isbn>
</book>
<book id="b2" author-id="a4">
<title>Test Book</title>
<published>1543</published>
</book>
</books>
</library>