以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XSL/XSLT/XSL-FO/CSS 』 (http://bbs.xml.org.cn/list.asp?boardid=8) ---- 求助: 关于xsl的问题! (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=50062) |
-- 作者:whitey -- 发布时间:7/17/2007 3:51:00 AM -- 求助: 关于xsl的问题! Hi, I am writing xslt to convert XML to XML, Please see the input XML I want to remove the dupleted note <kindOfLoss> in a <VINClaims>, the output XML should be like this, <VINData> How is the xslt work. |
-- 作者:火鸟 -- 发布时间:7/17/2007 11:13:00 AM -- done!相关xslt: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <VINData> <xsl:apply-templates /> </VINData> </xsl:template> <xsl:template match="//VINClaims"> <VINClaims> <dateOfLoss><xsl:value-of select="dateOfLoss"/></dateOfLoss> <xsl:for-each select="claimLoss"> <claimLoss> <kindOfLoss><xsl:value-of select="kindOfLoss"/></kindOfLoss> <lossAmount><xsl:value-of select="lossAmount"/></lossAmount> </claimLoss> </xsl:for-each> </VINClaims> </xsl:template> </xsl:stylesheet> |
-- 作者:whitey -- 发布时间:7/17/2007 11:41:00 AM -- thanks your help. but dupleted <kindOfLoss> are still there, how to get rid off them? |
-- 作者:火鸟 -- 发布时间:7/17/2007 12:02:00 PM -- 你的问题是个分组问题,我不熟。 |
-- 作者:Qr -- 发布时间:7/17/2007 6:16:00 PM -- done! <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <VINData> <xsl:apply-templates /> </VINData> </xsl:template> <xsl:template match="//VINClaims"> <VINClaims> <dateOfLoss><xsl:value-of select="dateOfLoss"/></dateOfLoss> <xsl:for-each select="claimLoss[not(preceding-sibling::*/kindOfLoss=kindOfLoss)]"> <claimLoss> <kindOfLoss><xsl:value-of select="kindOfLoss"/></kindOfLoss> <lossAmount><xsl:value-of select="lossAmount"/></lossAmount> </claimLoss> </xsl:for-each> </VINClaims> </xsl:template> </xsl:stylesheet>
|
-- 作者:whitey -- 发布时间:7/17/2007 9:32:00 PM -- Great!! You solved my problem. Thanks. |
-- 作者:whitey -- 发布时间:7/17/2007 10:38:00 PM -- Other question: How can I change above xslt for example out put: <VINClaims> <VINClaims> |
-- 作者:Qr -- 发布时间:7/18/2007 8:52:00 AM -- lossAmount的值可以通过sum()来统计,代码你就看着改吧,差不多的。 |
-- 作者:whitey -- 发布时间:7/18/2007 9:24:00 PM -- I try below,hopefully it is right way. But the variable name="lossAmount" always got "0", any idera? <xsl:variable name="lossAmount"> <xsl:value-of select="sum(claimLoss[(following- sibling::*/kindOfLoss=kindOfLoss)]/lossAmount)"/> </xsl:variable> |
-- 作者:whitey -- 发布时间:7/19/2007 1:04:00 AM -- it looks lwork if i use this <xsl:variable name="kindOfLoss"> <xsl:value-of select='kindOfLoss'/> </xsl:variable> <xsl:value-of select ="sum(claimLoss|following-sibling::*[kindOfLoss =$kindOfLoss]/lossAmount)"/> let me know if someone thinks it is wrong. |
-- 作者:Qr -- 发布时间:7/19/2007 5:33:00 PM -- <xsl:for-each select="claimLoss[not(preceding-sibling::*/kindOfLoss=kindOfLoss)]"> <xsl:variable name="curr" select="kindOfLoss"/> <claimLoss> <kindOfLoss><xsl:value-of select="kindOfLoss"/></kindOfLoss> <lossAmount> <xsl:value-of select="format-number(sum(../claimLoss[kindOfLoss=$curr]/lossAmount),'#.00')"/> </lossAmount> </claimLoss> </xsl:for-each>
|
-- 作者:whitey -- 发布时间:7/19/2007 9:52:00 PM -- Fantastic! Great place meet gereat people. |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
156.250ms |