如何对具有两个不同字典 xml 路径的 XML 文件进行 XSL 转换并将其转换为一个词典

问题描述 投票:0回答:1

XML 文件,其中包含两个词典的路径和徽标的路径。这些词典包含 10 个单词,每个英语单词和一个瑞典语单词。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lexikon.xsl"?>
<lexicon>
    <wordlist1>xml_english.xml</wordlist1>
    <wordlist2>xml_swedish.xml</wordlist2>
    <editor>Simon Bale</editor>
    <logo>logo.svg</logo>
</lexicon>

XML 英语词典

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xml_style.css"?>
<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>

XSL 文件

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xhtml1/strict" >
    <xsl:output
            method="xml"
            indent="yes"
            encoding="iso-8859-1"
    />

    <xsl:template match="/">
        <html>
            <head>
                <title>Lexicon</title>
                <link rel="stylesheet" type="text/css" href="xhtml_style.css"/> 
            </head>
            <body>
                <image src="logo.svg" alt="Logo"/>
                <h1><xsl:value-of select="/wordlist/language"/>
                </h1>
                <h2><xsl:value-of select="/wordlist/author"/>
                </h2>
                <ul> <!--en lista-->
                    <xsl:for-each select="/wordlist/words/word">
                        <li>
                            <xsl:value-of select="."/>
                        </li>
                    </xsl:for-each>
                </ul>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

我想将包含徽标和字典路径的 XML 文件转换为词典。但我陷入困境,不确定我做得是否正确。

xml xslt
1个回答
0
投票
<!-- transform.xsl -->

<!-- Define variables to hold the documents -->
<xsl:variable name="doc1" select="document('xml_english.xml')"/>
<xsl:variable name="doc2" select="document('xml_swedish.xml')"/>

<!-- Main template to process the merged documents -->
<xsl:template match="/">
    <output>
        <!-- Process content from doc1 -->
        <xsl:apply-templates select="$doc1/root/*"/>
        <!-- Process content from doc2 -->
        <xsl:apply-templates select="$doc2/root/*"/>
    </output>
</xsl:template>

<!-- Template to process nodes from doc1 -->
<xsl:template match="data">
    <!-- Customize processing as needed -->
    <processedData1>
        <xsl:value-of select="."/>
    </processedData1>
</xsl:template>

<!-- Template to process nodes from doc2 -->
<xsl:template match="data">
    <!-- Customize processing as needed -->
    <processedData2>
        <xsl:value-of select="."/>
    </processedData2>
</xsl:template>

© www.soinside.com 2019 - 2024. All rights reserved.