XML to XML with XSLT
Posted: Wed Jun 26, 2024 1:52 pm
Hi,
How do I XSL-transform two XML files containing words in two different languages and the result of the transformation will be a lexicon?
I have two XML files and each contains 10 words and SVG file which will be the logo of the lexicon. I need some help with the XSL file as it is not displaying any XML content from the files. Would appreciate if someone could take a look on this.
XML file 1: 10 Swedish words
XML file 2: 10 English words
XML file that has paths to the two above XML files and a SVG file
XSL file that will transform the XML files to a lexicon
How do I XSL-transform two XML files containing words in two different languages and the result of the transformation will be a lexicon?
I have two XML files and each contains 10 words and SVG file which will be the logo of the lexicon. I need some help with the XSL file as it is not displaying any XML content from the files. Would appreciate if someone could take a look on this.
XML file 1: 10 Swedish words
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="wordlist_style.css"?>
<wordlist>
<language>Svenska</language>
<author>Karl Jonsson</author>
<words>
<word>natt</word>
<word>dag</word>
<word>vatten</word>
<word>bil</word>
<word>sol</word>
<word>himmel</word>
<word>stad</word>
<word>hus</word>
<word>katt</word>
<word>regn</word>
</words>
</wordlist>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<wordlist>
<language>English</language>
<author>David Cahill</author>
<words>
<word>night</word>
<word>day</word>
<word>water</word>
<word>car</word>
<word>sun</word>
<word>sky</word>
<word>city</word>
<word>house</word>
<word>cat</word>
<word>rain</word>
</words>
</wordlist>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lexicon.xsl"?>
<dictionary>
<dictionaryLink>wordlist_english.xml</dictionaryLink>
<dictionaryLink>wordlist_swedish.xml</dictionaryLink>
<svgLogoLink>logo.svg</svgLogoLink>
</dictionary>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="dic1">
<xsl:value-of select="dictionary/dictionaryLink[1]"/>
</xsl:variable>
<xsl:variable name="dic2">
<xsl:value-of select="dictionary/dictionaryLink[2]"/>
</xsl:variable>
<xsl:variable name="logo">
<xsl:value-of select="dictionary/svgLogoLink"/>
</xsl:variable>
<xsl:template match="/dictionary">
<html>
<body>
<xsl:value-of select="document($dic1)/wordlist/@xml:lang" />
<br/>
<img src="{lexicon/logo}"/>
<h1>Swedish - English</h1>
<div class="left">
<h2>Swedish - English</h2>
<ul>
<xsl:for-each select="wordlist/word">
<li><xsl:value-of select="words"/></li>
</xsl:for-each>
</ul>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>