首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自2个XML的XSLT

来自2个XML的XSLT
EN

Stack Overflow用户
提问于 2013-04-09 08:21:04
回答 1查看 112关注 0票数 0

我是xslt高级程序的新手。实际上,对于从两个不同的xml文件生成xslt,我有一个疑问。

下面是我拥有的2个xml文件。

AHK-authors.xml

代码语言:javascript
复制
    <?xml version="1.0" encoding="UTF-8"?>
<chapters>
    <chapter no="1">
        <head-4>By J. R. Weeramantry</head-4>
    </chapter>
    <chapter no="2">
        <head-4>By Ernest Yang<footnote id="AHK-02.1.fn0" prefix="*">
                <footnote-para>I would like to acknowledge and express my gratitude for the assistance provided by my colleagues, Mr. Kevin Hong and Ms. Sharon Leung, in the preparation of this Chapter. All errors and omissions are my own. </footnote-para>
            </footnote>
        </head-4>
    </chapter>
    <chapter no="3">
        <head-4>By David Bateson and Edmund Wan</head-4>
    </chapter>
    <chapter no="4">
        <head-4>By Timothy Hill and Mark Lin</head-4>
    </chapter>
    <chapter no="5">
        <head-4>By Christopher To<footnote id="AHK-05.1.fn0" prefix="*">
                <footnote-para>I would like to acknowledge Alan Tang Siu Lun for his assistance in compiling parts of the Chapter.</footnote-para>
            </footnote>
        </head-4>
    </chapter>
    <chapter no="6">
        <head-4>By Chiann Bao</head-4>
    </chapter>
    <chapter no="7">
        <head-4>By Justin D’Agostino and Ula Cartwright-Finch</head-4>
    </chapter>
    <chapter no="8">
        <head-4>By Kim M. Rooney</head-4>
    </chapter>
    <chapter no="9">
        <head-4>By Neil Kaplan QC, JP, CBE, SBS and Andrew Aglionby</head-4>
        <head-5>[Revised and Updated by William Stone QC, SBS]<footnote id="AHK-09.1.fn0" prefix="*">
                <footnote-para>With thanks to summer students Chadwick Wong and Cheryl Leung.</footnote-para>
            </footnote>
        </head-5>
    </chapter>
    <chapter no="10">
        <head-4>By Frances van Eupen</head-4>
    </chapter>
    <chapter no="11">
        <head-4>By Peter Yuen and John Choong</head-4>
    </chapter>
    <chapter no="12">
        <head-4>By David Bateson and Edmund Wan</head-4>
    </chapter>
    <chapter no="13">
        <head-4>By Teresa Cheng SC<footnote id="AHK-13.1.fn0" prefix="*">
                <footnote-para>Special thanks to Andrew Aglionby, Joy Medd and Johnson Tan, co-authors to the first edition of this chapter, as portions of their work has been retained herein.</footnote-para>
            </footnote>
        </head-4>
    </chapter>
    <chapter no="14">
        <head-4>By Paul Starr<footnote id="AHK-14.1.fn0" prefix="*">
                <footnote-para>Heartfelt thanks to Jennifer Lee-Shoy, Stefania Lucchetti, Samuel Tang and Rita Wong.</footnote-para>
            </footnote>
        </head-4>
    </chapter>
    <chapter no="15">
        <head-4>By Timothy Hill and Mark Lin</head-4>
    </chapter>
    <chapter no="16">
        <head-4>By Denis Brock and Shirley Wu</head-4>
    </chapter>
    <chapter no="17">
        <head-4>By Peter Chow</head-4>
    </chapter>
    <chapter no="18">
        <head-4>By Paul Starr<footnote id="AHK-18.1.fn0" prefix="*">
                <footnote-para>Heartfelt thanks to Jennifer Lee-Shoy, Samuel Tang and Rita Wong for their assistance with this chapter.</footnote-para>
            </footnote>
        </head-4>
    </chapter>
    <chapter no="19">
        <head-4>By Kathryn Sanger, Joseph Chu and Bing Yu</head-4>
    </chapter>
    <chapter no="20">
        <head-4>By Loke-Khoon Tan</head-4>
    </chapter>
    <chapter no="21">
        <head-4>By Philip Yang and Rosita Lau</head-4>
    </chapter>
    <chapter no="22">
        <head-4>By Marianne Chao</head-4>
    </chapter>
    <chapter no="23">
        <head-4>By Dr Nils Eliasson</head-4>
    </chapter>
    <chapter no="24">
        <head-4>Banking, International Investor-State, Insurance, Property and Employment Disputes</head-4>
        <head-5>By Frances van Eupen, Vincent Li, Gary Soo and Alexander Stock</head-5>
    </chapter>
</chapters>

ARBHK-Chapter01.xml

代码语言:javascript
复制
    <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="xsl" ref="Untitled28.xslt"?>
<chapter num="A">
    <title>
        <content-style font-style="bold">PART 1 GENERAL PRINCIPLES</content-style>
    </title>
    <section level="sect1">
        <title>
            <content-style font-style="bold">Chapter 1: THE NEW ARBITRATION ORDINANCE</content-style>
        </title>
    </section>
</chapter>

我尝试过的xslt如下所示:Untitled28.xslt

代码语言:javascript
复制
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="html" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">

        <html>
            <head>
                <xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
                <title>
                    <xsl:value-of select="substring-after(chapter/section/title,':')"/>
                </title>
                <link rel="stylesheet" href="er:#css" type="text/css"/><xsl:text disable-output-escaping="yes"><![CDATA[</link>]]></xsl:text>
            </head>
            <body>
                <xsl:call-template name="new"/>
            </body>
        </html>
    </xsl:template>

<xsl:template match="chapters/chapter" name="new">
<div class="new">
<xsl:apply-templates select="document('AHK-authors.xml')/head-4">
</xsl:apply-templates>
</div>
</xsl:template> 
</xsl:stylesheet>

我得到的交货单如下

代码语言:javascript
复制
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </meta>
        <title> THE NEW ARBITRATION ORDINANCE</title>
        <link rel="stylesheet" href="er:#css" type="text/css"/>
    </head>
    <body>
        <div class="new"/>
    </body>
</html>

但我想列出所有作者的信息。

请告诉我该怎么做。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-09 08:51:56

检查您的XPath在您要查找"/head-4“的位置,您必须将它放在document元素或put // slash中,而不是应该工作的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15896814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档