XML 转换iTunes音乐库XML

<?xml version="1.0"?>
<xsl:stylesheet version = "1.0" 
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>

    <xsl:template match="/">
        <songlist>
            <xsl:apply-templates select="plist/dict/dict/dict"/>
        </songlist>
    </xsl:template>
    
    <xsl:template match="dict">
        <song>
            <xsl:apply-templates select="key"/>
        </song>
    </xsl:template>
    
    <xsl:template match="key">
        <xsl:element name="{translate(text(), ' ', '_')}">
            <xsl:value-of select="following-sibling::node()[1]"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

XML 将CSV数据加载到数据库中

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
  <connection id="in" driver="csv" url="data.csv" classpath="opencsv.jar"/>
  <connection id="out" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:ORCL" 
      classpath="ojdbc14.jar" user="scott" password="tiger"/>
  <!-- Copy all CSV rows to a database table -->
  <query connection-id="in">
      <!-- Empty query means select all columns -->
      <script connection-id="out">
          INSERT INTO Table_Name VALUES (?id,?priority, ?summary, ?status)
      </script>
  </query>
</etl>

XML XSLT从Excel XML电子表格中提取数据

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" /> 
  <xsl:variable name="title" select="/Workbook/Worksheet/@Name"/>	
  <xsl:template match="/">
    <html><head><title>Leisure Timetable</title></head>
      <body>
        <h1><xsl:value-of select="$title"/></h1>
        <xsl:apply-templates select="Workbook/Worksheet"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Worksheet">
    <xsl:apply-templates select="Table"/>
  </xsl:template> 

  <xsl:template match="Table">
    <table border="1">
      <xsl:apply-templates select="Row"/>
    </table>
  </xsl:template> 

  <xsl:template match="Row">
    <tr>
      <xsl:for-each select="Cell">
        <td><xsl:value-of select="." /></td>
      </xsl:for-each>
    </tr>
  </xsl:template> 

</xsl:stylesheet>

XML 适用于Spring MVC,hibernate过滤器和sitemesh Web应用程序的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="BioSafetyWebApp" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<display-name>Archetype Created Web Application</display-name>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			/WEB-INF/yourApplicationNameHere-context.xml 
			/WEB-INF/yourApplicationNameHere-servlet.xml
			/WEB-INF/yourApplicationNameHere-persistence.xml
			/WEB-INF/yourApplicationNameHere-security.xml
			/WEB-INF/yourApplicationNameHere-service.xml
		</param-value>
	</context-param>
	
	<servlet>
		<servlet-name>yourApplicationNameHere</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>yourApplicationNameHere</servlet-name>
		<url-pattern>*.htm</url-pattern>
	</servlet-mapping>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>	
	
	<filter>
		<filter-name>sitemesh</filter-name>
		<filter-class>
			com.opensymphony.module.sitemesh.filter.PageFilter
		</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>sitemesh</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>	

	<!-- Allows me to lazy load objects -->
	<filter>
		<filter-name>hibernateFilter</filter-name>
		<filter-class>
			org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
		</filter-class>
	</filter>	
	<filter-mapping>
		<filter-name>hibernateFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- Usually just does a jsp forward to a default action -->
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
	<!-- Commented out during development, it's easier to just see the app server blow up

	<error-page>
		<error-code>404</error-code>
		<location>/404.jsp</location>
	</error-page>
	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/error.jsp</location>
	</error-page>
	
	 -->
</web-app>

XML XSLT中的内置模板

<!-- Element or root node: Process children -->
<xsl:template match="* | /">
   <xsl:apply-templates /> 
</xsl:template> 

<!-- Element or root in specific mode: Process children in that mode -->
<xsl:template match="* | /" mode="m"> 
   <xsl:apply-templates mode="m" /> 
</xsl:template> 

<!-- Text or attribute node: Output value -->
<xsl:template match="text() | @*"> 
   <xsl:value-of select="." /> 
</xsl:template> 

<!-- PI or comment node: Hide from result -->
<xsl:template match="processing-instruction() | comment()" />

XML 在Mac OS X上设置虚拟主机(vhost)并正常重启Apache Web Server

//This is the code that goes in the vhosts.conf file (/private/etc/httpd/users/vhosts.conf)
//Substitute domain.web for domain you will use to access the vhost on your computer.
//For example, if I was working on cnn.com, I would change domain.web to cnn.web. For the
//document root I would change domain.com to cnn.com.

<VirtualHost *:80>
	ServerName domain.web
	DocumentRoot /Library/WebServer/Documents/domain.com/
</VirtualHost>

//This is the command line to be used in Terminal.app to restart Apache gracefully.

sudo apachectl -k graceful

XML XSLT Hello World

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/"> <h1>ROOT</h1> <xsl:apply-templates select="descendant::a"/> </xsl:template>

<xsl:template match="level0"> <xsl:value-of select="b"/> <p>Sum: <xsl:value-of select="descendant::l1e" /></p> <xsl:apply-templates select="level1"/> </xsl:template>

<xsl:template match="enum"> <option><xsl:value-of select="@match"/> - <xsl:value-of select="@name"/></option> </xsl:template>

<xsl:template match="level1"> <p>mult: <xsl:value-of select="l1e * ../b[3]" /></p> </xsl:template>

<xsl:template match="a"> <h4><xsl:value-of select="." /></h4> </xsl:template>

</xsl:stylesheet>