日志文章

2007年08月22日 22:31:26

XML与XSL的“匹配”问题

WYH桑在工作之中遇到的一个问题(由于没接触过且时间紧急,故请人帮助,嘿嘿,其实身边的我就会啊,在这方面包括JS等他还请教过我呢^_^),为了方便测试本人还是做了一个小练习。

内容是XSL与XML的“匹配”问题
A.XML文档如下:
<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="A.XSL" ?>

<Root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FirstName>Gao</FirstName>
<LastName>Xiao</LastName>
<Sex>Man</Sex>
<Birth>1983-06-03</Birth>
<Tel>010-12541254</Tel>
<Country>China</Country>
<City>BeiJing</City>
<Street>NanJing Road</Street>
<Salary>3000</Salary>
<Time>2008-12-01</Time>
</Root>

A.XSL文档如下:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="whatever">
<msxsl:script implements-prefix="user" language="Javascript">
<![CDATA[
function formatTime(strTime) {

  return strTime.substring(0,4) + strTime.substring(5,7) + strTime.substring(8,10) + strTime.substring(11,13) + strTime.substring(14,16);
}  

function formatDate(strDate) {
  return strDate.substring(0,4) + strDate.substring(5,7) + strDate.substring(8,10);
}

]]>

</msxsl:script>
<xsl:template match="Root">
<H2>XML-XSL</H2>
<SPAN>Name: </SPAN>
<Name>
<xsl:value-of select="FirstName"/><xsl:text>   </xsl:text><xsl:value-of select="LastName"/><BR/>
</Name>
<Birth>Birth:<xsl:value-of select="user:formatDate(string(Birth))"/></Birth> <BR/>
<Sex>Sex:
  <xsl:if test="Sex='False'">Women</xsl:if>
  <xsl:if test="Sex='True'">Man</xsl:if>
  <xsl:if test="Sex!='False' or Sex!='True' "><xsl:value-of select="Sex"/></xsl:if><BR/> </Sex>
<Tel>
<xsl:if test="Tel!=''">Phone:<xsl:value-of select="Tel"/></xsl:if>
</Tel>                                                                     <Address>  
<xsl:if test="Country!='' or City!='' or Street!='' ">Address:<xsl:value-of select="Street"/> <xsl:text> </xsl:text>
<xsl:value-of select="City"/> <xsl:text> </xsl:text>
<xsl:value-of select="Country"/> <xsl:text> </xsl:text>*
</xsl:if>
</Address>  
<Salary>Salary:
<xsl:value-of select="format-number(string(Salary),'00')"/><BR/>  
</Salary>
<Time>Time:<xsl:value-of select="user:formatTime(string(Time))"/></Time>

</xsl:template>
</xsl:stylesheet>
将二者放置于同一个目录下,在IE中浏览a.xml即可得到所需要的数据,结果如下:
XML-XSL
Name: Gao Xiao
Birth:19830603
Sex: Man
Phone:010-12541254
Address:NanJing Road BeiJing China *
Salary: 3000
Time:20081201

晚上看了中国女排与荷兰队的比较,真是着急(前2局输得可惜24:26,26:28),看了第三局赢了就闪,哈哈。

这几天面谈,加薪,呵呵,由于特殊时期,这些信息就保密不谈了,嘿嘿,不过稍稍偷漏一下,还可以,中上等(闲了半年多了和别人相比较还算不错,不过与本人的期望等等还是相差甚远,毕竟还是和面谈中所言,没有加薪,反倒是少给我三百/月的薪水……)^_^。其实薪水我并不敏感,关键是发展前景,至少目前而言,大宇宙满足不了我的"野心"。~



决定过些日子会学校看恩师—李兰友老师以及万振凯老师,尹慧老师,刘凤英老师等人,期待中……

Tags: XSL   薪水   大宇宙   中国女排  

类别: SoftWare |  评论(0) |  浏览(10372) |  收藏