原始文件如下:
<?xml version="1.0" encoding="utf-8"?>
<WMS_Capabilities>
<Service>
<Name>SIT WMS demo</Name>
<Title>SIT WMS demo</Title>
<Abstract>SIT WMS demo</Abstract>
<KeywordList>
<Keyword>WMS</Keyword>
<Keyword>SIT</Keyword>
<Keyword>ICT</Keyword>
</KeywordList>
</Service>
<Capability>
<Layer >
<Name>China</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>1222</TypeName>
<CRS>CRS:84</CRS>
<Layer >
<Name>Provinces</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>Provinces</TypeName>
<CRS>CRS:84</CRS>
<Layer >
<Name>Provinces</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>Provinces</TypeName>
<CRS>CRS:84</CRS>
</Layer>
</Layer>
<Layer >
<Name>China_point</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>China_line</TypeName>
<CRS/>
<Layer >
<Name>China_point</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>China_line</TypeName>
<CRS/>
</Layer>
</Layer>
<Layer >
<Name>China_point</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>China_point</TypeName>
<CRS>CRS:84</CRS>
</Layer>
</Layer>
</Capability>
</WMS_Capabilities>
转换文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/WMS_Capabilities/Capability/Layer"/>
</xsl:template>
<xsl:template match="Layer">
<xsl:param name="ID"/>
<xsl:variable name="variableId">
<xsl:value-of select="$ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="position()"/>
</xsl:variable>
<table>
<tbody>
<tr οnclick="javascript:doAction(this)">
<xsl:attribute name="id"><xsl:value-of select="substring($variableId,2,string-length($variableId))"/></xsl:attribute>
<th>Layer:</th>
<td>
<xsl:value-of select="./Name"/>
</td>
<td style="display:none">
<xsl:value-of select="./Title"/>
</td>
<td style="display:none">
<xsl:value-of select="./TypeName"/>
</td>
<td style="display:none">
<xsl:value-of select="./CRS"/>
</td>
</tr>
<tr>
<td> </td>
<td colspan="4">
<xsl:apply-templates select="Layer">
<xsl:with-param name="ID" select="$variableId"/>
</xsl:apply-templates>
</td>
</tr>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<WMS_Capabilities>
<Service>
<Name>SIT WMS demo</Name>
<Title>SIT WMS demo</Title>
<Abstract>SIT WMS demo</Abstract>
<KeywordList>
<Keyword>WMS</Keyword>
<Keyword>SIT</Keyword>
<Keyword>ICT</Keyword>
</KeywordList>
</Service>
<Capability>
<Layer >
<Name>China</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>1222</TypeName>
<CRS>CRS:84</CRS>
<Layer >
<Name>Provinces</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>Provinces</TypeName>
<CRS>CRS:84</CRS>
<Layer >
<Name>Provinces</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>Provinces</TypeName>
<CRS>CRS:84</CRS>
</Layer>
</Layer>
<Layer >
<Name>China_point</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>China_line</TypeName>
<CRS/>
<Layer >
<Name>China_point</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>China_line</TypeName>
<CRS/>
</Layer>
</Layer>
<Layer >
<Name>China_point</Name>
<Title>aggregation of 3 layers</Title>
<TypeName>China_point</TypeName>
<CRS>CRS:84</CRS>
</Layer>
</Layer>
</Capability>
</WMS_Capabilities>
转换文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/WMS_Capabilities/Capability/Layer"/>
</xsl:template>
<xsl:template match="Layer">
<xsl:param name="ID"/>
<xsl:variable name="variableId">
<xsl:value-of select="$ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="position()"/>
</xsl:variable>
<table>
<tbody>
<tr οnclick="javascript:doAction(this)">
<xsl:attribute name="id"><xsl:value-of select="substring($variableId,2,string-length($variableId))"/></xsl:attribute>
<th>Layer:</th>
<td>
<xsl:value-of select="./Name"/>
</td>
<td style="display:none">
<xsl:value-of select="./Title"/>
</td>
<td style="display:none">
<xsl:value-of select="./TypeName"/>
</td>
<td style="display:none">
<xsl:value-of select="./CRS"/>
</td>
</tr>
<tr>
<td> </td>
<td colspan="4">
<xsl:apply-templates select="Layer">
<xsl:with-param name="ID" select="$variableId"/>
</xsl:apply-templates>
</td>
</tr>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>