zoukankan      html  css  js  c++  java
  • 今天写的一个xslt解析xml为wml

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

    <xsl:template match="/root">
    <!-- Content Start -->
    <wml>
    <card id="show">
    <xsl:attribute name="title"><xsl:value-of select="@title" /></xsl:attribute>
    <p>

    <br/>
    <!--开始解析内容 -->
    <xsl:apply-templates select="content" />    
    </p>
    </card>
    </wml>
    <!-- Content End -->
    </xsl:template>
    <!--解析font标签 -->
    <xsl:template match="font">
    <xsl:element name="font">

    <xsl:choose>
    <xsl:when test="@size='large'">
    <xsl:attribute name="size">4</xsl:attribute>
    </xsl:when>
    <xsl:when test="@size='normal'">
    <xsl:attribute name="size">2</xsl:attribute>
    </xsl:when>
    <xsl:when test="@size='small'">
    <xsl:attribute name="size">1</xsl:attribute>
    </xsl:when>
    </xsl:choose>

    <xsl:attribute name="color">
    <xsl:value-of select="@color"></xsl:value-of>
    </xsl:attribute>

    <xsl:attribute name="align">
    <xsl:value-of select="@align"></xsl:value-of>
    </xsl:attribute>

    <xsl:value-of select="."></xsl:value-of>
    </xsl:element>
    </xsl:template>


    <!--解析a标签 -->
    <xsl:template match="a">
    <xsl:element name="a">
    <xsl:attribute name="href">
    <xsl:choose>
    <xsl:when test="substring-before(@href,':')='http'">
    <xsl:value-of select="@href"></xsl:value-of>
    </xsl:when>
    <xsl:when test="substring-before(@href,':')='tel'">
    <!--拨打电话 -->
    wtai://wp/mc;<xsl:value-of select="substring-after(@href,':')"></xsl:value-of>
    </xsl:when>
    <xsl:otherwise>
    http://<xsl:value-of select="@href"></xsl:value-of>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    <xsl:value-of select="."></xsl:value-of>
    </xsl:element>
    </xsl:template>


    <!--解析p标签 -->
    <xsl:template match="p">
    <xsl:element name="p">
    <xsl:attribute name="align">
    <xsl:value-of select="@align"></xsl:value-of>
    </xsl:attribute>
    <xsl:apply-templates select="" />    
    </xsl:element>
    </xsl:template>


    <!--可扩展增加需要解析的标签 -->


    </xsl:stylesheet>


    部分代码

  • 相关阅读:
    C++ Operate FTP
    md /mdd /ml /mt/mtd
    从MySpace基于.NET平台的六次重构经历,来感受分布式系统。
    分布式缓存BeIT Memcached简介
    Asp.Net应用程序中为什么要MachineKey?如何生成MachineKey?
    马云飞机上写长贴:再一次和新同事们谈谈看法
    memcached完全剖析
    ESET ESS/EAV 5 正式版 中英文32/64位 (注册版) 下载
    Windows下的.NET+ Memcached安装
    在 ASP.NET 環境下使用 Memcached 快速上手指南
  • 原文地址:https://www.cnblogs.com/yesun/p/485182.html
Copyright © 2011-2022 走看看