现在只剩下最后一个
f3
要输出了,同样的道理可以修改代码:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
<
?xml version='1.0'?
>
<
xsl:stylesheet
version=
"1.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
>
<
xsl:template
match=
"/"
>
<
xsl:apply-templates
select=
"root/item"
mode=
"a"
>
<
xsl:sort
select=
"@f1"
/
>
<
/xsl:apply-templates
>
<
/xsl:template
>
<
xsl:template
match=
"item"
mode=
"a"
>
<
xsl:if
test=
"not(preceding-sibling::*[@f1=current()/@f1])"
>
<
xsl:value-of
select=
"concat(@f1,'-')"
/
>
<
xsl:variable
name=
"f1"
select=
"@f1"
/
>
<
xsl:for-each
select=
".."
>
<
xsl:apply-templates
select=
"item[@f1 = $f1]"
mode=
"b"
>
<
xsl:sort
select=
"@f2"
/
>
<
/xsl:apply-templates
>
<
/xsl:for-each
>
<
br/
>
<
/xsl:if
>
<
/xsl:template
>
<
xsl:template
match=
"item"
mode=
"b"
>
<
xsl:if
test=
"not(preceding-sibling::*[@f2=current()/@f2])"
>
<
xsl:value-of
select=
"concat(' ',@f2,':')"
/
>
<
xsl:variable
name=
"f2"
select=
"@f2"
/
>
<
xsl:for-each
select=
".."
>
<
xsl:apply-templates
select=
"item[@f2 = $f2]"
mode=
"c"
>
<
xsl:sort
select=
"@f3"
/
>
<
/xsl:apply-templates
>
<
/xsl:for-each
>
<
/xsl:if
>
<
/xsl:template
>
<
xsl:template
match=
"item"
mode=
"c"
>
<
xsl:if
test=
"not(preceding-sibling::*[@f3=current()/@f3])"
>
<
xsl:if
test=
"position()!=1"
>
<
xsl:value-of
select=
"','"
/
>
<
/xsl:if
>
<
xsl:value-of
select=
"@f3"
/
>
<
/xsl:if
>
<
/xsl:template
>
<
/xsl:stylesheet
>
得到最终的输出:
江苏- 南京:fff,hhh 苏州
:bbb
山东- 济南:ddd,iii 青岛 :eee,ggg
浙江- 杭州:ccc 绍兴:aaa
山东- 济南:ddd,iii 青岛 :eee,ggg
浙江- 杭州:ccc 绍兴:aaa
OK,总算得到最终的结果了,但是是否完美了呢?或者说程序没有问题呢?
有问题,而且问题还很大。
转载于:https://blog.51cto.com/electiger/16817