首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xsl:在docbook xml文件中不工作的值

xsl:在docbook xml文件中不工作的值
EN

Stack Overflow用户
提问于 2022-07-12 17:33:43
回答 1查看 45关注 0票数 0

我在第5版中有以下docbook xml文件。

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<book version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
    <info>
        <title>Title1</title>
        <cover>
            <para>
                <para>a paragraph</para>
            </para>
        </cover>
    </info>
    <!-- Part A -->
    <part>
        <title>Part A</title>
        <chapter label="1">
            <title role="HEAD-1">Chapter1 from PartA</title>
            <para role="richtext">
                <para role="richtext"> Text in paragraph </para>
            </para>
        </chapter>
        <chapter label="2">
            <title role="HEAD-1">Chapter2 from partA</title>
            <para>Another paragraph</para>
        </chapter>
    </part>
    <!-- Part B -->
    <part>
        <title>Part B</title>
        <chapter label="1">
            <title role="HEAD-1">Chapter1 from PartB</title>
            <section>
                <title role="HEAD-2">Section1 from Chapter1 of PartB</title>
                <para>a paragraph <ulink url="http://alink2">a link2</ulink></para>
            </section>
            <section>
                <title role="HEAD-2">Section2 from Chapter1 of PartB</title>
                <para>a paragraph <ulink url="http://alink2">a link2</ulink></para>
            </section>
        </chapter>
    </part>
</book>

我试图通过xslt v3和修改特定元素将其转换为html (我已经为java使用了saxon库),即

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:db="http://docbook.org/ns/docbook"
        xmlns:m="http://docbook.org/ns/docbook/modes"
        xmlns:h="http://www.w3.org/1999/xhtml"
        xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl xs db m h"
        version="3.0">

    <xsl:import href="https://cdn.docbook.org/release/xsltng/current/xslt/docbook.xsl" />


    <xsl:template match="db:part" mode="m:docbook">
        

        <xsl:variable name="title1" select="title" />
        <xsl:variable name="title2" select="./title"/>
        <xsl:variable name="title3" select="./db:title"/>
        <xsl:variable name="title4" select="/db:title"/>
        <xsl:variable name="title5" select="db:title"/>
        <xsl:variable name="title6" select="xs:title"/>
        <xsl:variable name="title7" select="xsl:title"/>
        <xsl:variable name="title8" select="/title"/>
        <xsl:variable name="title9" select="./h:title"/>
        <xsl:variable name="title10" select="h:title"/>




        <section class="part">
            <h1 class="title">
                title1:<xsl:value-of select = "$title1"/>
                title2:<xsl:value-of select = "$title2"/>
                title3:<xsl:value-of select = "$title3"/>
                title4:<xsl:value-of select = "$title4"/>
                title5:<xsl:value-of select = "$title5"/>
                title6:<xsl:value-of select = "$title6"/>
                title7:<xsl:value-of select = "$title7"/>
                title8:<xsl:value-of select = "$title8"/>
                title9:<xsl:value-of select = "$title9"/>
                title10:<xsl:value-of select = "$title10"/>
            </h1>
            <xsl:next-match/>
        </section>
    </xsl:template>
</xsl:stylesheet>

我想得到这个头衔,但出于某种原因,它没有任何价值。我尝试过不同的方法,认为是错误的命名空间,但它似乎不是什么东西。

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-12 19:58:33

我不知道DocBook的样式表在访问模板之前应该如何处理源输入XML,但是如果在模板中执行<xsl:message select="."/>,就会看到结构发生了变化。

代码语言:javascript
复制
<part xmlns="http://docbook.org/ns/docbook"
       xmlns:xi="http://www.w3.org/2001/XInclude">
   <info>
      <title>Part A</title>
   </info>
   <chapter label="1">
      <info>
         <title role="HEAD-1">Chapter1 from PartA</title>
      </info>
      <para role="richtext">
         <para role="richtext"> Text in paragraph </para>
      </para>
   </chapter>
   <chapter label="2">
      <info>
         <title role="HEAD-1">Chapter2 from partA</title>
      </info>
      <para>Another paragraph</para>
   </chapter>
</part>

其中,title已包装到info元素中。因此,在这一点上,任何子选择db:title都不会选择任何东西,您需要db:info/db:title,我认为。

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

https://stackoverflow.com/questions/72956288

复制
相关文章

相似问题

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