Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 为什么';我的XSL在这个XML中找不到要处理的内容吗?_Xslt_Cognos - Fatal编程技术网

Xslt 为什么';我的XSL在这个XML中找不到要处理的内容吗?

Xslt 为什么';我的XSL在这个XML中找不到要处理的内容吗?,xslt,cognos,Xslt,Cognos,为什么我的XSL在这个XML中找不到任何要处理的东西?我正在尝试将CognosXML报告输出转换为另一种形式(是的,我知道cognos生成html,但我需要其他东西)。它只产生“Caption:”一词,然后停止 以下是我的XSL: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://developer.cognos.com/sch

为什么我的XSL在这个XML中找不到任何要处理的东西?我正在尝试将CognosXML报告输出转换为另一种形式(是的,我知道cognos生成html,但我需要其他东西)。它只产生“Caption:”一词,然后停止

以下是我的XSL:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">

    <xsl:template match="/">

    <xsl:template match="rows">
        <xsl:apply-templates select="rowEdge"/>
    </xsl:template>

    <xsl:template match="rowEdge">
        <b>Caption:</b> <xsl:value-of select="caption"/><br/>
        <xsl:if test="@id">
            <b>id:</b> <xsl:value-of select="@id"/><br/>
        </xsl:if>
        <xsl:if test="rowEdge">
            <xsl:apply-templates select="rowEdge"/>
        </xsl:if>
    </xsl:template>

    <html>
        <head><title>%s</title></head>
        <body>
            <xsl:apply-templates select="dataset/crosstab/rows"/>
        </body>
    </html>

    </xsl:template>
</xsl:stylesheet> 

标题:
id:
%
以下是XML(我不得不删除一些,但应该给出一个想法):


0
12.61728395
1320.40677966
7.
1.90318499
108.66456135
776.61407946
-0.86007907 
46.53571429
时间段:DCG已发生支付年度
2002年1月至12月{所有数据}CRxIp
2002
会员平均年龄
每个脚本接收的供应天数
每名员工的净薪酬
急性发作的天数
急性发作的天数
允许Amt PMPM Med和Rx{Cmpl}
允许Amt PMPM Med和Rx{Cmpl}
%差异允许金额PMPM Med和Rx{Cmpl}
相对风险评分Prosp Explan非标度
子集
计划类型Medstat
队列医疗统计
慢性发作
HMO(管理式护理)
女性,1岁
在XSLT1.0(您正在使用)中,XPath表达式中不考虑默认名称空间

您需要做的是:

1) 在XSLT转换中为实例文档的默认命名空间指定前缀,例如:

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="cog:http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">

看起来你的根模板有点混乱-底部的html部分应该转到第一个模板吗?谢谢。我还必须以这种方式调用它:递归不起作用,它只是打印出第一行边缘的整个文本(父+子)并退出。好吧,我重点讨论了名称空间问题,这是一个非常常见的问题,但看看您的XSLT,我发现还有另一个问题:您不能像现在这样在模板中嵌入模板!要解决此问题,需要将嵌入的模板移出根节点(/)的模板,并在所有XPath表达式中的所有元素名称之前添加前缀。
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="cog:http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="cog:rowEdge">
    <b>Caption:</b> <xsl:value-of select="cog:caption"/><br/>
    <xsl:if test="@id">
       <b>id:</b> <xsl:value-of select="@id"/><br/>
    </xsl:if>
    <xsl:if test="cog:rowEdge">
        <xsl:apply-templates select="cog:rowEdge"/>
    </xsl:if>
</xsl:template>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cog="http://developer.cognos.com/schemas/xmldata/1/" version="1.0">

    <xsl:template match="/">

        <html>
            <head>
                <title>%s</title>
            </head>
            <body>
                <xsl:apply-templates select="cog:dataset/cog:crosstab/cog:rows"/>
            </body>
        </html>

    </xsl:template>

    <xsl:template match="cog:rows">
        <xsl:apply-templates select="cog:rowEdge"/>
    </xsl:template>

    <xsl:template match="cog:rowEdge">
        <b>Caption:</b>
        <xsl:value-of select="cog:caption"/>
        <br/>
        <xsl:if test="@id">
            <b>id:</b>
            <xsl:value-of select="@id"/>
            <br/>
        </xsl:if>
        <xsl:apply-templates select="cog:rowEdge"/>
    </xsl:template>

</xsl:stylesheet>