Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自SAP的XML(ATOM)使用XSL在HTML表中显示多个属性(在同一元素中)时出现问题_Xml_Xslt_Sap - Fatal编程技术网

来自SAP的XML(ATOM)使用XSL在HTML表中显示多个属性(在同一元素中)时出现问题

来自SAP的XML(ATOM)使用XSL在HTML表中显示多个属性(在同一元素中)时出现问题,xml,xslt,sap,Xml,Xslt,Sap,嗨,我对XML非常陌生 我正在尝试使用XSL将XML转换为HTML。Internet Explorer一直显示空白。 XML是由我为实践而构建的SAP演示系统生成的。 我所期望的结果是一个HTML表,它将保存一行中每个元素的6个左右属性 下面的XML: <edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/

嗨,我对XML非常陌生

我正在尝试使用XSL将XML转换为HTML。Internet Explorer一直显示空白。 XML是由我为实践而构建的SAP演示系统生成的。 我所期望的结果是一个HTML表,它将保存一行中每个元素的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>
<?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>



下面的XSL:

<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>
<?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>



SAP航班
系统名称
承运人ID
承运人名称
货币代码
统一资源定位地址

您必须考虑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>

SAP航班
系统名称
承运人ID
承运人名称
货币代码
统一资源定位地址
在这里
看到它在这里工作:


至于为什么看不到任何输出,您是如何运行XSLT转换的?

我也将作为一个副本来结束它。您已经落入了数百人都会落入的陷阱(您可以通过搜索“XSLT默认名称空间”来找到它们)。以复本结尾并不是批评,因为在不知道答案的情况下,你不可能知道所有其他问题,但是当其他人进行搜索时,将其标记为复本有助于清理空间。