用XSLT文件在浏览器格式化显示XML文件

XMLSpy编辑XSDDTDXMLXSLT文件非常方便,altova公司还提供了Home Edition免费版提供下载。

首先定义一个描述ComponentXML Schema文件

<?xml version="1.0" encoding="UTF-8" ?>

<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by ibm (ibm) -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:col="http://www.novacolimas.com/colimas/namespace"

targetNamespace="http://www.novacolimas.com/colimas/namespace" elementFormDefault="qualified"

attributeFormDefault="unqualified">

<xs:element name="ComponentsBasicInfo">

<xs:annotation>

<xs:documentation>Title: cbi.xsd

Subject: the component basic information.

Publisher: Nova Corporation, Colimas.

Format: text/xml

Creator: Zhao Lei

Date.Created: 2005-04-23

Language: en-US

Description:

Change Log:

Version Date Modifier Description

01.00 2005/04/25 Zhao Lei Initial release.

</xs:documentation>

</xs:annotation>

<xs:complexType>

<xs:sequence>

<xs:element name="ComponentBasicInfo" minOccurs="0" maxOccurs="unbounded">

<xs:complexType>

<xs:sequence>

<xs:element name="SerialNo">

<xs:annotation>

<xs:documentation>Component SerialNo, 27 characters with a-z or A-Z or 0-9</xs:documentation>

</xs:annotation>

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value="[a-zA-Z0-9]{27}" />

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:element name="Name" type="xs:string">

<xs:annotation>

<xs:documentation>Component Name</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Alias" type="xs:string">

<xs:annotation>

<xs:documentation>Component Alias</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="Version" default="1.0">

<xs:annotation>

<xs:documentation>Component Version</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="DevelopmentLanguage" type="xs:string">

<xs:annotation>

<xs:documentation>Component Development Language</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="DevelopmentPlatform" type="xs:string" />

<xs:element name="Authors" type="xs:string" />

<xs:element name="Status" default="Unconfirmed">

<xs:annotation>

<xs:documentation>the status of component: Unconfirmed | Confirmed | Deleted</xs:documentation>

</xs:annotation>

<xs:simpleType>

<xs:restriction base="xs:string">

<xs:pattern value="Unconfirmed|Confirmed|Deleted" />

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:element name="ConfirmDate" type="xs:dateTime" />

<xs:element name="ConfirmBy" type="xs:string" />

<xs:element name="CreateDate" type="xs:dateTime" />

<xs:element name="CreateBy" type="xs:string" />

<xs:element name="LastChangeDate" type="xs:dateTime" />

<xs:element name="LastChangeBy" type="xs:string" />

<xs:element name="BrowseTimes" type="xs:integer" default="0" />

<xs:element name="IsPublic" type="xs:boolean" default="true">

<xs:annotation>

<xs:documentation>whether the component is public</xs:documentation>

</xs:annotation>

</xs:element>

<xs:element name="DevelopmentEnvironment" type="xs:string" />

<xs:element name="FunctionDescription" type="xs:string" />

<xs:element name="Developers">

<xs:simpleType>

<xs:restriction base="xs:string" />

</xs:simpleType>

</xs:element>

<xs:element name="Admins">

<xs:simpleType>

<xs:restriction base="xs:string" />

</xs:simpleType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

XMLSpy编辑一个cbi.xsdxml文件:cbidebug.xml

<?xml version="1.0" encoding="UTF-16"?>

<?xml-stylesheet type="text/xsl" href="component.xslt"?>

<ComponentsBasicInfo xmlns="http://www.novacolimas.com/colimas/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.novacolimas.com/colimas/namespace

C:\DOCUME~1\Administrator\MYDOCU~1\NovaPlan\Colimas\ID\XSD\cbi.xsd">

<ComponentBasicInfo>

<SerialNo>aaaaaaaaaaaaaaaaaaaaaaaaaaa</SerialNo>

<Name>Mactintosh</Name>

<Alias>Mactintosh component</Alias>

<Version>1.0</Version>

<DevelopmentLanguage>Java</DevelopmentLanguage>

<DevelopmentPlatform>Linux</DevelopmentPlatform>

<Authors> , </Authors>

<Status>Unconfirmed</Status>

<ConfirmDate>2001-12-17T09:30:47.0Z</ConfirmDate>

<ConfirmBy>String</ConfirmBy>

<CreateDate>2001-12-17T09:30:47.0Z</CreateDate>

<CreateBy>String</CreateBy>

<LastChangeDate>2001-12-17T09:30:47.0Z</LastChangeDate>

<LastChangeBy>String</LastChangeBy>

<BrowseTimes>123</BrowseTimes>

<IsPublic>true</IsPublic>

<DevelopmentEnvironment>WSAD,XML, Websphere, DB2, WebSphere MQ, AIXCPU is Intel</DevelopmentEnvironment>

<FunctionDescription>Component Function Description.</FunctionDescription>

<Developers>Lei Zhao, Herry Chow</Developers>

<Admins>Lei Zhao</Admins>

</ComponentBasicInfo>

</ComponentsBasicInfo>

接着定义XSLT文件:component.xslt

其中<xsl:variable name="componentinfo.cominfo" select="'Component Information'"/>

select值可以更换为其他语言。

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:col="http://www.novacolimas.com/colimas/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:variable name="componentinfo.cominfo" select="'Component Information'"/>

<xsl:variable name="template.edit" select="'Edit!'"/>

<xsl:variable name="template.down" select="'Download'"/>

<xsl:variable name="template.confirm" select="'Confirm!'"/>

<xsl:variable name="template.del" select="'Delete!'"/>

<xsl:variable name="componentinfo.fundesc" select="'Function Description'"/>

<xsl:variable name="componentinfo.deven" selectfont-size: 10pt; color: blue; font-

你可能感兴趣的:(xml,浏览器,AIX,websphere,XSL)