从XML生成XSLT(Generate XSLT FROM XML)

编程入门 行业动态 更新时间:2024-10-28 20:25:28
XML生成XSLT(Generate XSLT FROM XML)

我正在从XML创建XLST文件。 我已经回顾了W3schools和许多其他帖子,但我找到的所有内容似乎都指向基本的XLST语法。 我认为我正在做的事情很简单。 以下XML是我需要帮助创建XLST文件的项目示例:

<?xml version="1.0" encoding="UTF-8"?> <Order> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:06:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166800</Quantity> <Cost>1668</Cost> <ID type="width">20</ID> <ID type="length">30</ID> <Info> <Id type="ClientCode">Ac</Id> <Name>Arthur</Name> </Info> </AllInfo> </Item> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:07:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166</Quantity> <Cost>15</Cost> <ID type="width">20</ID> <Info> <Id type="ClientCode">Ad</Id> <Name>Lynx</Name> </Info> </AllInfo> <SupplementalData> <Items> <Color>Red</Color> </Items> </SupplementalData> </Item> </Order>

我希望XLST的输出如下表所示:

I am in the process of creating an XLST file from an XML. I have reviewed W3schools and many other posts but everything I find seems to point to basic XLST syntax. I assume what I am doing is simple though. The following XML is an example of the items I need help creating an XLST file for is:

<?xml version="1.0" encoding="UTF-8"?> <Order> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:06:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166800</Quantity> <Cost>1668</Cost> <ID type="width">20</ID> <ID type="length">30</ID> <Info> <Id type="ClientCode">Ac</Id> <Name>Arthur</Name> </Info> </AllInfo> </Item> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:07:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166</Quantity> <Cost>15</Cost> <ID type="width">20</ID> <Info> <Id type="ClientCode">Ad</Id> <Name>Lynx</Name> </Info> </AllInfo> <SupplementalData> <Items> <Color>Red</Color> </Items> </SupplementalData> </Item> </Order>

I want the output of the XLST to look like the following table:

最满意答案

对于XML

<Order> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:06:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166800</Quantity> <Cost>1668</Cost> <ID type="width">20</ID> <ID type="length">30</ID> <Info> <Id type="ClientCode">Ac</Id> <Name>Arthur</Name> </Info> </AllInfo> </Item> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:07:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166</Quantity> <Cost>15</Cost> <ID type="width">20</ID> <Info> <Id type="ClientCode">Ad</Id> <Name>Lynx</Name> </Info> </AllInfo> <SupplementalData> <Items> <Color>Red</Color> </Items> </SupplementalData> </Item> </Order>

和XSLT

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> </head> <body> <table border="1"> <tr bgcolor="#9acd32"> <th>Name</th> <th>Date Time</th> <th>Quantity</th> <th>Cost</th> <th>width</th> <th>length</th> <th>Client code</th> <th>Name</th> <th>Color</th> </tr> <xsl:for-each select="Order/Item"> <tr> <td><xsl:value-of select="GeneralInfo/Name"/></td> <td><xsl:value-of select="GeneralInfo/DateTime"/></td> <td align="right"><xsl:value-of select="AllInfo/Quantity"/></td> <td align="right"><xsl:value-of select="AllInfo/Cost"/></td> <td align="right"><xsl:value-of select="AllInfo/ID[@type='width']"/></td> <td align="right"><xsl:value-of select="AllInfo/ID[@type='length']"/></td> <td><xsl:value-of select="AllInfo/Info/Id[@type='ClientCode']"/></td> <td><xsl:value-of select="AllInfo/Info/Name"/></td> <td><xsl:value-of select="SupplementalData/Items/Color"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

For XML

<Order> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:06:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166800</Quantity> <Cost>1668</Cost> <ID type="width">20</ID> <ID type="length">30</ID> <Info> <Id type="ClientCode">Ac</Id> <Name>Arthur</Name> </Info> </AllInfo> </Item> <Item Version="2"> <GeneralInfo> <Name>TW</Name> <DateTime format="YYYY-MM-DD-HH:MM:SS">2017-04-17-17:07:36</DateTime> </GeneralInfo> <AllInfo> <Quantity>166</Quantity> <Cost>15</Cost> <ID type="width">20</ID> <Info> <Id type="ClientCode">Ad</Id> <Name>Lynx</Name> </Info> </AllInfo> <SupplementalData> <Items> <Color>Red</Color> </Items> </SupplementalData> </Item> </Order>

and XSLT

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head> </head> <body> <table border="1"> <tr bgcolor="#9acd32"> <th>Name</th> <th>Date Time</th> <th>Quantity</th> <th>Cost</th> <th>width</th> <th>length</th> <th>Client code</th> <th>Name</th> <th>Color</th> </tr> <xsl:for-each select="Order/Item"> <tr> <td><xsl:value-of select="GeneralInfo/Name"/></td> <td><xsl:value-of select="GeneralInfo/DateTime"/></td> <td align="right"><xsl:value-of select="AllInfo/Quantity"/></td> <td align="right"><xsl:value-of select="AllInfo/Cost"/></td> <td align="right"><xsl:value-of select="AllInfo/ID[@type='width']"/></td> <td align="right"><xsl:value-of select="AllInfo/ID[@type='length']"/></td> <td><xsl:value-of select="AllInfo/Info/Id[@type='ClientCode']"/></td> <td><xsl:value-of select="AllInfo/Info/Name"/></td> <td><xsl:value-of select="SupplementalData/Items/Color"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

更多推荐

XLST,XML,电脑培训,计算机培训,IT培训"/> <meta name="description" co

本文发布于:2023-04-27 23:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329244.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:XML   XSLT   Generate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!