[XSLT难题 No.2]

CrazyJavar 2003-08-20 04:15:18
给定一个字符串参数,比如"pk",需要列出源xml文档中所有名称最后部分是"pk"的属性的元素来

比如
<A abcpk="123">
<B defpk="456"/>
<C ghipkjk="789"/>
<D pklmn="101112"/>
</A>

通过xslt需要把
<A abcpk="123">
<B defpk="456">
给列出来

请问在下面的xslt文件中应该如何实现呢

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="key">pk</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select="node()"/>
</xsl:template>
<xsl:template match="node()">
<xsl:for-each select="@*">
<xsl:if test="这里应该如何实现">
<!--这里应该如何实现-->
</xsl:if>
</xsl:for-each>
<xsl:apply-templates select="node()"/>
</xsl:template>
</xsl:stylesheet>



...全文
36 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CrazyJavar 2003-08-21
  • 打赏
  • 举报
回复
2楼的朋友写的我在XMLSpy里查了一下好想没有用啊

一楼的可以

还是谢谢二位
ssm1226 2003-08-20
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="csdn0037.xsl"?>
<root>
<A abcpk="123">
<B defpk="456"/>
<C ghipkjk="789"/>
<D pklmn="101112"/>
</A>
</root>


csdn0037.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" media-type="text/xml" omit-xml-declaration="yes"/>
<xsl:param name="key" select="'pk'"/>
<xsl:template match="node()">
<xsl:variable name="ifcontains">
<xsl:call-template name="blnTrue">
<xsl:with-param name="attTemps" select='@*'/>
<xsl:with-param name="pos" select="'1'"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$ifcontains='true'">
<xsl:copy>
<xsl:copy-of select="@*" />
</xsl:copy>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:template>

<xsl:template name="blnTrue">
<xsl:param name="attTemps"/>
<xsl:param name="pos"/>
<xsl:variable name="attTemp" select="$attTemps[$pos]"/>
<xsl:variable name="attName" select="local-name($attTemp)"/>
<xsl:choose>
<xsl:when test="contains($attName,$key) and substring-after($attName,$key)=''">
<xsl:value-of select="'true'"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$attTemps[$pos+1]">
<xsl:call-template name="blnTrue">
<xsl:with-param name="attTemps" select="$attTemps"/>
<xsl:with-param name="pos" select="$pos+1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Patrick_DK 2003-08-20
  • 打赏
  • 举报
回复
<xsl:for-each select="@*">
<xsl:if test="string($language) = (substring(name(), string-length(name()) - string-length(string($language)) + 1, string-length(name())))">
<h1>
<xsl:value-of select="name()"/>
</h1>
</xsl:if>
</xsl:for-each>

8,906

社区成员

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

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