【问题标题】:Issue with namespaces in XSLT TranslationXSLT 翻译中的命名空间问题
【发布时间】:2017-11-13 17:18:35
【问题描述】:

*我发现问题似乎是因为这条线

xmlns="http://sample.com/task/1.0"

没有分配命名空间,当我添加一个 (ns1) 时,事情似乎按照我想要的方式进行了翻译。我修改后的问题是“为什么没有分配命名空间有问题,如果我想在许多文件中更改它,我该怎么做?”

我是 XSLT 的新手,但我正在尝试获取 XML 文档并将其转换为 RDF。我的方法是从一个简单的翻译开始,以纯文本形式提取一些 XML 术语。我获取了一个 XML 文件,去掉了名称空间,并且能够正确显示内容。

在本次迭代中,我将命名空间添加回 XML 文件,但不让它们在标签中被引用。我还将它们添加到 XSL 文件中。当我运行翻译时,我只得到我在值之前写的文本。但是,当我将 xsl:template 匹配更改为“/*”之外的任何内容时,我得到的是值而不是文本。这是代码

XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<getCollectiveTaskResponse xmlns="http://sample.com/task/1.0" xmlns:ns2="http://sample.com/commonElements/1.0" xmlns:ns3="http://sample.com/individualTask/1.0" xmlns:ns4="http://sample.com/collectiveTask/1.0" xmlns:ns5="http://sample.com/xsd/handle" xmlns:ns6="http://sample.com/appinfo/1">
<collectiveTask>
    <generalInformation>
        <number>13</number>
        <title>Quarterback</title>
        <name>Dan Marino</name>
    </generalInformation>    </collectiveTask>

这里是 XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://sample.com/task/1.0"     xmlns:ns2="http://sample.com/commonElements/1.0"     xmlns:ns3="http://sample.com/individualTask/1.0" xmlns:ns4="http://sample.com/collectiveTask/1.0" xmlns:ns5="http://sample.com/xsd/handle" xmlns:ns6="http://sample.com/appinfo/1">
<xsl:template match="/getCollectiveTaskResponse">



Number:<xsl:value-of select="collectiveTask/generalInformation/number"/>
Title:<xsl:value-of select="collectiveTask/generalInformation/title"/>
Name:<xsl:value-of select="collectiveTask/generalInformation/name"/>

</xsl:template>



</xsl:stylesheet>

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    如果您使用的是 XSLT 2 或 3 处理器,则制作您的模板

    <xsl:template match="/getCollectiveTaskResponse">
    
    
    
    Number:<xsl:value-of select="collectiveTask/generalInformation/number"/>
    Title:<xsl:value-of select="collectiveTask/generalInformation/title"/>
    Name:<xsl:value-of select="collectiveTask/generalInformation/name"/>
    
    </xsl:template>
    

    您需要将xpath-default-namespace="http://sample.com/task/1.0" 放在xsl:stylesheet 元素上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多