XSLT 中的 XPATH - DITA XML 文件

发布于 2024-10-08 22:39:38 字数 684 浏览 6 评论 0原文

我有一个名为“map.xml”的 XML,它调用另一个 xml“map1.xml”。Map.xml 引用了 map.xsl。

在XSLT中,我需要编写代码来获取map1.xml中存在的节点值?你们中的任何人都可以为此建议一个解决方案吗?

以下代码特定于 DITA 标准

map1.xml:

    <?xml version="1.0" encoding="UTF-8"?>
       <!-- code to refer XSLT -->
          <map title="DITA Topic Map">
  <topicref href="client.xml"/>
       </map>

map2.xml:

    <?xml version="1.0" encoding="UTF-8"?>
     <concept id="map2">
 <title>Client Rights</title>
 <conbody>
  <p>Part of your job as a healthcare provider.</p>
 </conbody>
       </concept>

I have a XML called "map.xml" which calls another xml "map1.xml".Map.xml has reference to map.xsl.

In XSLT, i need to write the code to get the node value present in map1.xml? Can anyone of you please suggest a solution for this?

Below code specific to DITA standards

map1.xml:

    <?xml version="1.0" encoding="UTF-8"?>
       <!-- code to refer XSLT -->
          <map title="DITA Topic Map">
  <topicref href="client.xml"/>
       </map>

map2.xml:

    <?xml version="1.0" encoding="UTF-8"?>
     <concept id="map2">
 <title>Client Rights</title>
 <conbody>
  <p>Part of your job as a healthcare provider.</p>
 </conbody>
       </concept>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╰ゝ天使的微笑 2024-10-15 22:39:38

使用 XSLT document() 函数看起来是一个不错的选择。

例如,要获取 map2.xml 中 p 元素的内容/值:

<xsl:value-of select="document('map2.xml')/concept/conbody/p"/>

尚未在您的示例中对此进行测试,但这就是我会尝试的!

Using the XSLT document() function looks like the way to go.

For example, to get the content/value of the p element in map2.xml:

<xsl:value-of select="document('map2.xml')/concept/conbody/p"/>

Have not tested this on your example, but that's what I would try!

岛歌少女 2024-10-15 22:39:38

使用 XSLT document() 函数访问单独 XML 文档中的节点。可以在此处找到一个简单的示例(由 w3schools.com 提供)。

我是新用户,所以 SO 阻止我在答案中发布第二个链接。这是我能做的最好的事情:XSLT 标准对 document() 的解释可以在 www.w3.org/TR/xslt#document 上找到。

Use the XSLT document() function to access nodes in a separate XML document. A simple example (courtesy of w3schools.com) can be found here.

I'm a new user, so SO is preventing me from posting a second link in my answer. Here's the best I can do: the XSLT standard's explanation of document() can be found at www.w3.org/TR/xslt#document.

强辩 2024-10-15 22:39:38

我认为,源实际上应该看起来像这样(引用 DTD 或模式,而不是样式表):

map.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map title="DITA Topic Map">
  <topicref href="client.xml"/>
</map>

client.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="client.xml">
 <title>Client Rights</title>
 <conbody>
  <p>Part of your job as a healthcare provider.</p>
 </conbody>
</concept>

David 的建议是正确的,它为您提供以下结果:

Part of your job as a healthcare provider.

对此进行改进:要利用 DITA 的专业化功能,您宁愿使用如下内容:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

<xsl:output omit-xml-declaration="yes"/>

<xsl:template match="*[contains(@class, ' map/topicref ') and @href]">
    <xsl:variable name="topic" select="document(@href, .)"/>
    <xsl:value-of select="$topic//*[contains(@class, ' topic/p ')]"/>
</xsl:template>

</xsl:stylesheet>

对于示例数据,这会产生相同的结果。但是如果您有一个专门的段落元素

派生,您仍然可以对新元素使用相同的转换。

I think, the sources should actually look like this (with a reference to a DTD or a schema, not to a styleheet):

map.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map title="DITA Topic Map">
  <topicref href="client.xml"/>
</map>

client.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="client.xml">
 <title>Client Rights</title>
 <conbody>
  <p>Part of your job as a healthcare provider.</p>
 </conbody>
</concept>

David's suggestion is correct, it gives you the following result:

Part of your job as a healthcare provider.

To refine on this: To make use of DITA's specialization feature, you'd rather use something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

<xsl:output omit-xml-declaration="yes"/>

<xsl:template match="*[contains(@class, ' map/topicref ') and @href]">
    <xsl:variable name="topic" select="document(@href, .)"/>
    <xsl:value-of select="$topic//*[contains(@class, ' topic/p ')]"/>
</xsl:template>

</xsl:stylesheet>

With the sample data, this leads to the same result. But if you had a specialized paragraph element <myp> derived from <p>, you could still use the same transformation for the new element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文