在test中,如何判断节点属性的值是否等于某个字符?

peppi 2002-10-06 04:47:11
有一XML:

<top>
<table>
<tr name="date">
<ITEM>
<text>654</text>
</ITEM>
</tr>
</table>
<table>
<tr name="logo">
<logo>
agd
</logo>
</tr>
</table>
</top>

我想根据<tr>的属性的不同值,做不同的XSLT处理
我的XSL:

<xsl:template match="top">
<body>
<xsl:choose>
<xsl:when test="string(table/tr/@name) = logo">
<xsl:apply-templates select="table" mode="logo"/>
</xsl:when>
<xsl:when test="string(table/tr/@name) = date">
<xsl:apply-templates select="table" mode="date"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="table" mode="others"/>
</xsl:otherwise>
</xsl:choose>
</body>
</xsl:template>

<xsl:template match="table" mode="logo">
<table width="97%" border="0" align="center" cellspacing="0"> <xsl:apply-templates select="tr" mode="logo"/>
</table>
</xsl:template>

<xsl:template match="table" mode="date">
<table width="100%" border="0" align="center" cellspacing="0">
<xsl:apply-templates select="tr" mode="date"/>
</table>
</xsl:template>

有错误,我估计问题在<xsl:when test="string(table/tr/@name) = logo">,test中该怎么判断某个节点的属性值是什么呢?我把string()去掉也不行,我换成table/tr/@name/text()也不行,换成test="table/tr[@name=logo]"也是不行,各位,我有两个要求:
一:给个正确答案
二:告诉我为什么以上那几个不行,问题在哪?帮我解解疑
谢谢!!!
...全文
224 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
outside 2002-10-09
  • 打赏
  • 举报
回复
<xsl:template match="top">中只对第一个<table>做处理


修改如下:
<xsl:template match="top">
<body>
<xsl:for-each select="table">
<xsl:if test="tr/@name= 'logo'">
<xsl:apply-templates select="tr" mode="logo"/>
</xsl:if>
<xsl:if test="tr/@name = 'date'">
<xsl:apply-templates select="tr" mode="date"/>
</xsl:if>
</xsl:for-each>
</body>
</xsl:template>


<xsl:template match="tr" mode="logo"> <!--处理LOGO-->
<table><tr><td>
<xsl:attribute name="bgcolor">
<xsl:value-of select="bgcolor"/>
</xsl:attribute>
<xsl:apply-templates select="logo|companypic"/>
</td>
</tr>
</table>
</xsl:template>

<xsl:template match="tr" mode="date"> <!--处理时间-->
<table>
<tr><td>
<xsl:attribute name="bgcolor">
<xsl:value-of select="'red'"/>
</xsl:attribute>
<xsl:attribute name="align">
<xsl:value-of select="location"/>
</xsl:attribute>
<xsl:apply-templates select="ITEM" mode="date"/>
</td></tr>
</table>
</xsl:template>
peppi 2002-10-07
  • 打赏
  • 举报
回复
您受累了~~~~~~

<xsl:template match="top">
<body>
<xsl:if test="string(table/tr/@name) = 'logo'">
<xsl:apply-templates select="table" mode="logo"/>
</xsl:if>
<xsl:if test="string(table/tr/@name) = 'date'">
<xsl:apply-templates select="table" mode="date"/>
</xsl:if>
</body>
</xsl:template>

<xsl:template match="table" mode="logo">
<table width="97%" border="0" align="center">
<xsl:apply-templates select="tr" mode="logo"/>
</table>
</xsl:template>

<xsl:template match="table" mode="date">
<table width="100%" border="0" align="center">
<xsl:apply-templates select="tr" mode="date"/>
</table>
</xsl:template>

<xsl:template match="tr" mode="logo"> <!--处理LOGO-->
<tr>
<xsl:attribute name="bgcolor">
<xsl:value-of select="bgcolor"/>
</xsl:attribute>
<xsl:apply-templates select="logo|companypic"/>
</tr>
</xsl:template>

<xsl:template match="tr" mode="date"> <!--处理时间-->
<tr>
<xsl:attribute name="bgcolor">
<xsl:value-of select="bgcolor"/>
</xsl:attribute>
<xsl:attribute name="align">
<xsl:value-of select="location"/>
</xsl:attribute>
<xsl:apply-templates select="ITEM" mode="date"/>
</tr>
</xsl:template>

在显示tr时,就会遇到我上面说的问题.很是奇怪.我不知道我哪里搞错了,请您指点!
孟子E章 2002-10-07
  • 打赏
  • 举报
回复
把你的xsl拿来
peppi 2002-10-06
  • 打赏
  • 举报
回复
孟先生:
谢谢指点.我现在把<xsl:when>换成<xsl:if>然后把<xsl:choose>去掉.我要根据@name的不同,输出不同的HTML,如XSL所写.可是我遇到一个问题,我用相应的XSL去单独解释任何一个table节点,都正常显示,但把他们加到一起,如果第一个XML的table和XSL中的第一个table模板对应,那就只显示它一个,后面的只有一个HTML中的table,而且属性是和前面的一样,但就没下文了.如果XML和XSL的table顺序不一样,它还不显示.这是怎么搞的?该怎么解决?才能让两个XML中的table都按XSL中的显示出来?
谢谢~
孟子E章 2002-10-06
  • 打赏
  • 举报
回复
<xsl:choose>
<xsl:when test="string(table/tr/@name) = 'logo'">
<xsl:apply-templates select="table" mode="logo"/>
</xsl:when>
<xsl:when test="string(table/tr/@name) = 'date'">
<xsl:apply-templates select="table" mode="date"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="table" mode="others"/>
</xsl:otherwise>
</xsl:choose>
孟子E章 2002-10-06
  • 打赏
  • 举报
回复
<xsl:when test="string(table/tr/@name) = 'logo'">,
内容概要:本文围绕“单相逆变器闭环逆变电路PWM模型仿真研究”展开,基于Simulink平台构建单相逆变器的闭环控制系统仿真模型,重点研究PWM调制技术在逆变电路的应用与实现。文详细阐述了系统架构设计、电压电流双闭环控制策略的实现原理、控制器参数设计及仿真建模全过程,并通过仿真结果验证了控制方案在动态响应、稳态精度与系统稳定性方面的有效性。同时,文档还涵盖多种电力电子系统典型应用场景,如多类型短路故障仿真(性点不接地、经小电阻接地、经消弧线圈接地等)、软开关技术、微电网能量管理、MPPT控制等,体现出较强的技术综合性和工程实践价。; 适合人群:电气工程、自动化、电力电子与新能源等相关专业的高校本科生、研究生、科研人员,以及从事电力系统仿真、逆变器设计与新能源并网技术研发的工程技术人员。; 使用场景及目标:①掌握基于Simulink的单相逆变器闭环控制系统建模与PWM仿真方法;②深入理解双闭环控制、SPWM/SVPWM调制、系统稳定性分析等核心技术原理;③为课程设计、毕业设计、科研项目或实际工程开发提供可复用的仿真模型与技术支持; 阅读建议:建议结合文仿真模型动手实践,重点掌握PI控制器参数整定、PWM信号生成机制与仿真结果分析方法,同时可延伸学习文档涉及的软开关、故障仿真、微电网控制等关联技术,以拓展系统级设计能力。

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧