用xsl 可生成递归id的程序

原始文件如下:
<?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>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值