来自 SAP 的 XML(ATOM) 使用 XSL 在 HTML table 中显示多个属性(在同一元素内)的问题
Problem with XML(ATOM) from SAP using XSL to Display Multiple Attributes(within same element) in a HTML table
嗨,我是 XML 的新手。
我正在尝试使用 XSL 将 XML 转换为 HTML。 Internet Explorer 一直显示空白。
XML 是由我为练习构建的 SAP 演示系统生成的。
我期望的结果是 HTML table 它将连续保存每个元素的 6 个左右属性。
XML 下面:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ZSFLIGHT_PROJECT_SRV" xml:lang="en" sap:schema-version="1">
<?xml-stylesheet type="text/xsl" href="xml_from_sap.xsl"?>
<EntityType Name="Carrier" sap:content-version="1">
<Key>
<PropertyRef Name="Carrid"/>
</Key>
<Property Name="Mandt" Type="Edm.String" Nullable="false" MaxLength="3" sap:unicode="false" sap:label="Client" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Carrid" Type="Edm.String" Nullable="false" MaxLength="3" sap:unicode="false" sap:label="Airline" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Carrname" Type="Edm.String" Nullable="false" MaxLength="20" sap:unicode="false" sap:label="Airline" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Currcode" Type="Edm.String" Nullable="false" MaxLength="5" sap:unicode="false" sap:label="Airline Currency" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:semantics="currency-code"/>
<Property Name="Url" Type="Edm.String" Nullable="false" MaxLength="255" sap:unicode="false" sap:label="URL" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
</EntityType>
<EntityContainer Name="ZSFLIGHT_PROJECT_SRV_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="CarrierSet" EntityType="ZSFLIGHT_PROJECT_SRV.Carrier" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:addressable="false" sap:content-version="1"/>
<EntitySet Name="Carriers" EntityType="ZSFLIGHT_PROJECT_SRV.Carrier" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:addressable="false" sap:content-version="1"/>
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="self" href="http://vhcalnplci:8000/sap/opu/odata/sap/ZSFLIGHT_PROJECT_SRV/$metadata"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="latest-version" href="http://vhcalnplci:8000/sap/opu/odata/sap/ZSFLIGHT_PROJECT_SRV/$metadata"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
XSL 下面:
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>SAP Flights</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Sytem Name</th>
<th>Carrier ID</th>
<th>Carrier Name</th>
<th>Currency Code</th>
<th>URL</th>
</tr>
<xsl:for-each select = "EntityType/Property">
<tr>
<td><xsl:value-of select = "@Name"/></td>
<td><xsl:value-of select = "@Type"/></td>
<td><xsl:value-of select = "@Nullable"/></td>
<td><xsl:value-of select = "@MaxLength"/></td>
<td><xsl:value-of select = "@Name"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
您必须考虑 XML 文件中元素的命名空间。
执行此操作的方法如下:
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
xmlns:edm="http://schemas.microsoft.com/ado/2008/09/edm"
exclude-result-prefixes="edm edmx">
<xsl:output method="html" indent="yes"/>
<xsl:template match = "/">
<html>
<body>
<h2>SAP Flights</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Sytem Name</th>
<th>Carrier ID</th>
<th>Carrier Name</th>
<th>Currency Code</th>
<th>URL</th>
</tr>
<xsl:for-each select = "edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType/edm:Property">
<tr><td>Here</td></tr>
<tr>
<td><xsl:value-of select = "@Name"/></td>
<td><xsl:value-of select = "@Type"/></td>
<td><xsl:value-of select = "@Nullable"/></td>
<td><xsl:value-of select = "@MaxLength"/></td>
<td><xsl:value-of select = "@Name"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
看到它在这里工作:https://xsltfiddle.liberty-development.net/bEzknt4
至于为什么您没有看到任何输出,您 运行 XSLT 转换如何?
嗨,我是 XML 的新手。
我正在尝试使用 XSL 将 XML 转换为 HTML。 Internet Explorer 一直显示空白。 XML 是由我为练习构建的 SAP 演示系统生成的。 我期望的结果是 HTML table 它将连续保存每个元素的 6 个左右属性。
XML 下面:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ZSFLIGHT_PROJECT_SRV" xml:lang="en" sap:schema-version="1">
<?xml-stylesheet type="text/xsl" href="xml_from_sap.xsl"?>
<EntityType Name="Carrier" sap:content-version="1">
<Key>
<PropertyRef Name="Carrid"/>
</Key>
<Property Name="Mandt" Type="Edm.String" Nullable="false" MaxLength="3" sap:unicode="false" sap:label="Client" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Carrid" Type="Edm.String" Nullable="false" MaxLength="3" sap:unicode="false" sap:label="Airline" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Carrname" Type="Edm.String" Nullable="false" MaxLength="20" sap:unicode="false" sap:label="Airline" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Currcode" Type="Edm.String" Nullable="false" MaxLength="5" sap:unicode="false" sap:label="Airline Currency" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:semantics="currency-code"/>
<Property Name="Url" Type="Edm.String" Nullable="false" MaxLength="255" sap:unicode="false" sap:label="URL" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
</EntityType>
<EntityContainer Name="ZSFLIGHT_PROJECT_SRV_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="CarrierSet" EntityType="ZSFLIGHT_PROJECT_SRV.Carrier" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:addressable="false" sap:content-version="1"/>
<EntitySet Name="Carriers" EntityType="ZSFLIGHT_PROJECT_SRV.Carrier" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:pageable="false" sap:addressable="false" sap:content-version="1"/>
</EntityContainer>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="self" href="http://vhcalnplci:8000/sap/opu/odata/sap/ZSFLIGHT_PROJECT_SRV/$metadata"/>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="latest-version" href="http://vhcalnplci:8000/sap/opu/odata/sap/ZSFLIGHT_PROJECT_SRV/$metadata"/>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
XSL 下面:
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>SAP Flights</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Sytem Name</th>
<th>Carrier ID</th>
<th>Carrier Name</th>
<th>Currency Code</th>
<th>URL</th>
</tr>
<xsl:for-each select = "EntityType/Property">
<tr>
<td><xsl:value-of select = "@Name"/></td>
<td><xsl:value-of select = "@Type"/></td>
<td><xsl:value-of select = "@Nullable"/></td>
<td><xsl:value-of select = "@MaxLength"/></td>
<td><xsl:value-of select = "@Name"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
您必须考虑 XML 文件中元素的命名空间。 执行此操作的方法如下:
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
xmlns:edm="http://schemas.microsoft.com/ado/2008/09/edm"
exclude-result-prefixes="edm edmx">
<xsl:output method="html" indent="yes"/>
<xsl:template match = "/">
<html>
<body>
<h2>SAP Flights</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Sytem Name</th>
<th>Carrier ID</th>
<th>Carrier Name</th>
<th>Currency Code</th>
<th>URL</th>
</tr>
<xsl:for-each select = "edmx:Edmx/edmx:DataServices/edm:Schema/edm:EntityType/edm:Property">
<tr><td>Here</td></tr>
<tr>
<td><xsl:value-of select = "@Name"/></td>
<td><xsl:value-of select = "@Type"/></td>
<td><xsl:value-of select = "@Nullable"/></td>
<td><xsl:value-of select = "@MaxLength"/></td>
<td><xsl:value-of select = "@Name"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
看到它在这里工作:https://xsltfiddle.liberty-development.net/bEzknt4
至于为什么您没有看到任何输出,您 运行 XSLT 转换如何?