XSLT 忽略模板中的元素?
我有以下 XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="ss:Workbook/o:DocumentProperties/o:*"/>
<xsl:template match="ss:Workbook/x:ExcelWorkbook/x:*"/>
<xsl:template match="ss:Workbook/x:ExcelWorkbook/x:*"/>
<xsl:template match="ss:Workbook/ss:Worksheet/x:WorksheetOptions/x:*"/>
<xsl:template match="ss:Workbook/ss:DocumentProperties/ss:*"/>
<xsl:template match='ss:Workbook/ss:Worksheet/ss:Table'>
<grade-dist>
<xsl:apply-templates select='ss:Workbook/ss:Worksheet/ss:Table'/>
</grade-dist>
</xsl:template>
<xsl:template match='ss:Workbook/ss:Worksheet/ss:Table'>
....
我的 XML 输出正常,但我没有:
和 在其中,似乎它完全忽略了两者,知道为什么吗?
谢谢,
I have the following XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="ss:Workbook/o:DocumentProperties/o:*"/>
<xsl:template match="ss:Workbook/x:ExcelWorkbook/x:*"/>
<xsl:template match="ss:Workbook/x:ExcelWorkbook/x:*"/>
<xsl:template match="ss:Workbook/ss:Worksheet/x:WorksheetOptions/x:*"/>
<xsl:template match="ss:Workbook/ss:DocumentProperties/ss:*"/>
<xsl:template match='ss:Workbook/ss:Worksheet/ss:Table'>
<grade-dist>
<xsl:apply-templates select='ss:Workbook/ss:Worksheet/ss:Table'/>
</grade-dist>
</xsl:template>
<xsl:template match='ss:Workbook/ss:Worksheet/ss:Table'>
....
My XML outputs fine, but I dont have the: <grade-dist>
and </grade-dist>
in it, seems like it ignores both completely, any idea why?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两个具有完全相同匹配模式的模板:
'ss:Workbook/ss:Worksheet/ss:Table'
根据 XSLT 规范,这是一个可恢复的错误,此处观察到的恢复是模板最后才被选中。
另一个观察结果是,指令:
在匹配
'sss:Workbook/ss:Worksheet/ss:Table'
的模板内,很可能是错误的 -- 不太可能有'ss:Workbook/ss:Worksheet/ss:Table'
元素具有'ss:Workbook/ss:Worksheet/ss:Table'< /code> 曾祖父母。
我认为你想要的是这样的:
或者只是:
You have two templates with exactly the same match pattern:
'ss:Workbook/ss:Worksheet/ss:Table'
According to the XSLT spec this is a recoverable error and the recovery observed here is that the template that comes last get chosen.
Another observation is that the instruction:
inside the template matching
'ss:Workbook/ss:Worksheet/ss:Table'
, is most probably wrong -- it is unlikely that there would be'ss:Workbook/ss:Worksheet/ss:Table'
elements that have a'ss:Workbook/ss:Worksheet/ss:Table'
grand-grand-parent.I think what you want is something like this:
or just:
看起来好像您有两个匹配条件相同的模板(即没有模式或优先级属性来区分它们)。如果处理器绕过第一个并处理第二个,因为它“获胜”,那么这将产生您正在观察的效果(因为我假设等级距离内应用模板的目的是调用第二个模板) 。
It looks as if you have two templates whose match criteria are identical (i.e., no mode or priority attributes to differentiate them). If the processor is bypassing the first one and processing the second because it "wins," then this would have the effect you are observing (since I presume the purpose of the apply-templates inside the grade-dist is to invoke the second template).