写一个XSL模板递归示例
2007/1/15 21:52:42
阅读全文(8322) | 回复(1) | 编辑 | 精华
递归.xml <?xml version="1.0" encoding="gb2312" ?><?xml-stylesheet type="text/xsl" href="递归.xsl" ?><root> <str>1行/n2行/n3行/n</str></root> 递归.xsl <?xml version="1.0" encoding="gb2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <xsl:apply-templates select="//str"/></xsl:template><xsl:template match="str"><xsl:call-template name="temp"> <xsl:with-param name="str" select="."/></xsl:call-template></xsl:template> <xsl:template name="temp"> <xsl:param name="str"/> <xsl:if test="string-length($str) > 0"> <xsl:value-of select="substring($str , 1 , number(string-length(substring-before($str,'/n'))))"/><br/> <xsl:call-template name="temp"> <xsl:with-param name="str" select="substring( $str , number(string-length(substring-before($str,'/n')))+3 , number(string-length($str)))"/> </xsl:call-template> </xsl:if></xsl:template></xsl:stylesheet>
Posted by Qr on 2007/1/15 21:52:42
回复:写一个XSL模板递归示例
2008/1/29 20:28:28
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
solidluck的递归: <?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="hello.xsl"?><root><data><row>我们是我们有钱我们人我们</row></data><data><row>我们他们是我们我们的</row></data><data> <row>很我们厉害的我们</row> </data> <keyword>我们</keyword></root> <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version="1.0"> <xsl:output method="html" encoding="utf-8" indent="yes" /> <xsl:template match="/"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>红色高亮</title> </head> <body> <xsl:for-each select="root/data"> <xsl:call-template name="red"> <xsl:with-param name="color">#ff0000</xsl:with-param> <xsl:with-param name="keyword" select="../keyword" /> <xsl:with-param name="content" select="row" /> </xsl:call-template> </xsl:for-each> </body> </html> </xsl:template> <xsl:template name="red"> <xsl:param name="color" /> <xsl:param name="keyword" /> <xsl:param name="content" /> <xsl:choose> <xsl:when test="contains($content,$keyword)"> <xsl:value-of select="substring-before($content,$keyword)" /> <font style="color:{$color};"> <xsl:value-of select="string($keyword)" /> </font> <xsl:call-template name="red"> <xsl:with-param name="color" select="string($color)" /> <xsl:with-param name="keyword" select="string($keyword)" /> <xsl:with-param name="content" select="substring-after($content,$keyword)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$content" /> <br /> </xsl:otherwise> </xsl:choose> </xsl:template></xsl:stylesheet>
Qr(游客)
Posted by Qr(游客) on 2008/1/29 20:28:28
发表评论: |
|