You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用XSL表达式在Dita Map中获取pubtitle值

获取DITA Map中的pubtitle值的XSL表达式

Got it, let's break down how to grab that pubtitle value from your DITA Map using XSL expressions. First, let's clarify your input DITA Map structure (formatted for readability):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pubmap PUBLIC "urn:pubid:com.sam.doctypes:dita:pubmap" "pubmap.dtd">
<pubmap xml:lang="en-US">
  <pubtitle>
    <mainpubtitle outputclass="book">Sample Word</mainpubtitle>
  </pubtitle>
  <topicref href="topics/topic_1.dita">
    <topicmeta>
      <navtitle>Ram-Files-Raj (RFR)</navtitle>
      <metadata>...</metadata>
    </topicmeta>
  </topicref>
</pubmap>

核心XPath表达式(适配XPath 1.0/2.0)

Since your DITA Map doesn't use a custom namespace, these expressions will work directly:

  • 提取<mainpubtitle>的文本内容(这是你大概率需要的"pubtitle值"):

    /pubmap/pubtitle/mainpubtitle/text()
    

    This will return the raw text: Sample Word

  • 过滤带指定outputclass属性的<mainpubtitle>(如果有多个mainpubtitle元素,确保你拿到的是标记为"book"的那个):

    /pubmap/pubtitle/mainpubtitle[@outputclass='book']/text()
    
  • 获取整个<mainpubtitle>元素(如果你需要包含属性和文本的完整元素节点):

    /pubmap/pubtitle/mainpubtitle
    

完整XSLT示例

Here's a simple XSLT stylesheet that demonstrates extracting and outputting the pubtitle value:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <extracted-pubtitle>
            <!-- Use the filtered XPath if you need to target the book-specific title -->
            <xsl:value-of select="/pubmap/pubtitle/mainpubtitle[@outputclass='book']/text()"/>
        </extracted-pubtitle>
    </xsl:template>
</xsl:stylesheet>

注意:如果你的DITA Map使用命名空间

If your full DITA Map includes a default namespace (e.g., xmlns="http://dita.oasis-open.org/architecture/2005/"), you'll need to declare the namespace in your XSLT and prefix the element names:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dita="http://dita.oasis-open.org/architecture/2005/">
    <xsl:template match="/">
        <extracted-pubtitle>
            <xsl:value-of select="/dita:pubmap/dita:pubtitle/dita:mainpubtitle[@outputclass='book']/text()"/>
        </extracted-pubtitle>
    </xsl:template>
</xsl:stylesheet>

内容的提问来源于stack exchange,提问作者User515

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:00:47