Thursday, April 29, 2010

StudyNote--I DML--XML XPath XSLT

<?xml version="1.0" encoding="UTF-8"?>
<!--copyright(c) by sksc.me -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="wordlist">
<Dictionary xsi:noNamespaceSchemaLocation="translation.xsd">
<!--noNamespaceSchemaLocation可以作为Dictionary的属性赋值-->
   <from>
     <xsl:value-of select="upper-case(/wordlist/@from)" />
   </from>
   <to>
     <xsl:value-of select="upper-case(/wordlist/@to)"/>
   </to>
   <total>
    <xsl:value-of select="count(/wordlist/wordEntry/search[not(.=following::search)])"/>
   </total>
  <xsl:for-each select="/wordlist/wordEntry">
   <xsl:sort select="search"/>
    <xsl:if test="generate-id(.)=generate-id(../wordEntry[search=current()/search])">
          <xsl:element name="translation">
              <xsl:attribute name="initial">
                <xsl:value-of select="substring(search,1,1)"/>
                <!--get the first letter of search term as the content of initial -->
              </xsl:attribute>            
              <xsl:element name="search">
                 <xsl:value-of select="search"/>
              </xsl:element>
              <counter>
                <xsl:value-of select="count(../wordEntry[search=current()/search][not(.=following::wordEntry)])"/>
              </counter>
              <xsl:for-each select="../wordEntry[search=current()/search][not(.=following::wordEntry)]">
                    <xsl:sort select="replace"/>
                 <xsl:copy-of select="replace"/>
              </xsl:for-each>
          </xsl:element>
     </xsl:if>
  </xsl:for-each>
</Dictionary>
</xsl:template>
</xsl:stylesheet>

Labels: , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home