【问题标题】:XSLT - Substitute code for stringXSLT - 字符串的替代代码
【发布时间】:2015-09-22 16:45:45
【问题描述】:

我正在一个程序中处理 XSLT,它使用 XML 1.0。所以,因为它在一个程序中,所以我不能使用其他语言来做到这一点。 在程序中,我可以选择一些关于我的数据的选项,但我无法从 xslt 获取它。代码现在是这样的:

<!-- MD_DataIdentification.topicCategory-->
<div class="itemInfo">
       <span style="color: black; font-size: 13;">
       <span style="color: black; font-size: 15; font-weight:bold;">Categoria temática:<br /></span>
    <xsl:choose>
        <xsl:when test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '001') and (. != '002') and (. != '003') and (. != '004') and (. != '005') and (. != '006') and (. != '007') and (. != '008') and (. != '009') and (. != '010')]">
            <xsl:for-each select="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '001') and (. != '002') and (. != '003') and (. != '004') and (. != '005') and (. != '006') and (. != '007') and (. != '008') and (. != '009') and (. != '010')]">
                <xsl:value-of select="."/>
                <xsl:if test="not(position()=last())">, </xsl:if>
            </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
            <span class="noContent">No information (mandatory)</span>
        </xsl:otherwise>
        </xsl:choose>
    </span>
</div>

我从“for-each”中得到的答案是我选择的一些空格。我想做的是将代码与它所代表的信息相关联。比如 001 = 农业,002 = 生物,003 = 经济,等等。任何人都可以帮助我吗?如何强制 xslt 显示代码名称? 我尝试执行此代码,但它不起作用:

    <xsl:choose>
        <xsl:when test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '001') and (. != '002') and (. != '003') and (. != '004') and (. != '005') and (. != '006') and (. != '007') and (. != '008') and (. != '009') and (. != '010')]">
        <xsl:if test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '001')]">
         Farming |
        </xsl:if>   
        <xsl:if test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '002')]">
         Biologic |
        </xsl:if>   
        <xsl:if test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '003')]">
        Boundaries |
        </xsl:if>
        <xsl:if test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '004')]">
        Atmospheric |
        </xsl:if>
        <xsl:if test="/metadata/dataIdInfo[1]/tpCat/TopicCatCd[(. != '005')]">
        Economy |
        </xsl:if>
       </xsl:when>
       </xsl:choose>

但是当我使用它时,我会收到所有未导入的名称,无论它是否被选中。 如果有人可以帮助我,我将不胜感激。 :)


我还有一个问题。在这个 中,重点是什么?谢谢!

【问题讨论】:

  • 您能否包含一个示例 XML 文档? XPath 中的点. 是当前节点的别名。

标签: xml xslt arcgis


【解决方案1】:

很难回答您的问题,因为您没有提供任何上下文或预期的输出。一般来说,给定这样的输入:

XML

<root>
    <code>001</code>
    <code>002</code>
    <code>003</code>
    <code>004</code>
    <code>005</code>
</root>

还有一个样式表:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>

<xsl:template match="/root">
    <div>
        <xsl:for-each select="code">
            <xsl:choose>
                <xsl:when test=". = '001'">farming</xsl:when>
                <xsl:when test=". = '002'">biologic</xsl:when>
                <xsl:when test=". = '003'">economic</xsl:when>
                <xsl:otherwise>
                    <span class="noContent">No information (mandatory)</span>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="position() != last()">, </xsl:if>
        </xsl:for-each>
    </div>
</xsl:template>

</xsl:stylesheet>

结果将是:

<div>farming, biologic, economic, <span class="noContent">No information (mandatory)</span>, <span class="noContent">No information (mandatory)</span></div>

【讨论】:

  • 嗨 michael.horn257k,感谢您的帮助。我在这里尝试,但我仍然有同样的问题。我为文本选择了四个选项,当我运行 xslt 时,我会收到所有人的农业信息。我会更新我的问题,检查一下。谢谢。
  • @EduardoPereira 我无法解决我看不到的代码。
猜你喜欢
  • 2014-01-22
  • 2023-03-11
  • 1970-01-01
  • 2015-10-07
  • 2012-06-26
  • 2011-03-05
  • 2012-07-29
  • 1970-01-01
相关资源
最近更新 更多