XSLT转换格式

时间:2018-04-09 05:04:00

标签: xml xslt

所以,基本上我试图在我的xml中显示描述,就像在picture中一样。我创建了我的.xml,.dtd,.css和.xslt以及this我当前的.xml看起来像。令我困惑的是我对每本书都有不同的描述。

这是我的xml的一部分

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE items SYSTEM "workshop.dtd">
<?xml-stylesheet type="text/xsl" href="workshop.xslt"?>
<items> 
    <item type="ebook">
        <title>Cyber-assurance for the internet of things</title>
        <author>
            <authorname>Tyson T. Brooks</authorname>
            <authorlink>https://ecu.on.worldcat.org/search?queryString=au:Tyson T. Brooks&amp;databaseList=3200,1461,2110,2108,2229,1931,2107,3838,3839,1697,3313,3036,1937,638,2507,1978,2109,3494,2481,3371,2513,3129,3404,2237,2038,2236,3369,1861,1982,2433,2795,2233,3967,2210,2375,2175,2570,3384,2051,3382,1953,1875,2007,2447,2006,2209,1834,2462,3034,3197,2261,2062,2260,1842,2259,3227,3502,2059,2211,3909</authorlink>
            <authorlink2></authorlink2>
        </author>
        <year>2017</year>
        <type>ebook</type>
        <thumbnail>cyberassurance.jpg</thumbnail>
        <link>https://ecu.on.worldcat.org/oclc/966445296</link>
        <description>
                    Publication:Hoboken, New Jersey : Wiley : IEEE Press, [2017]
                    Physical:   1 online resource
                    Language:   English 
                    Staff View: MARC Record 
                    ISBN:       9781119193784 1119193788 9781119193883 1119193885 9781119193876 1119193877 
                    OCLC Number: 966445296 
                    Contents:   Embedded Design Security. Certified Security by Design for the Internet of Things / Shiu-Kai Chin -- Cyber-Assurance Through Embedded Security for the Internet of Things / Tyson T Brooks, Joon Park -- A Secure Update Mechanism for Internet of Things Devices / Martin Goldberg -- Trust Impact. Security and Trust Management for the Internet of Things: An Rfid and Sensor Network Perspective / M Bala Krishna -- The Impact of IoT Devices on Network Trust Boundaries / Nicole Newmeyer -- Wearable Automation Provenance. Wearable IoT Computing: Interface, Emotions, Wearer'S Culture, and Security/Privacy Concerns / Robert Mccloud, Martha Lerski, Joon Park, Tyson T Brooks -- On Vulnerabilities of IoT-Based Consumer-Oriented Closed-Loop Control Automation Systems / Martin Murillo -- Big Data Complex Event Processing for Internet of Things Provenance: Benefits for Audit, Forensics, and Safety / Mark Underwood -- Cloud Artificial Intelligence Cyber-Physical Systems. A Steady-State Framework for Assessing Security Mechanisms in a Cloud-of-Things Architecture / Tyson T Brooks, Lee McKnight -- An Artificial Intelligence Perspective on Ensuring Cyber-Assurance for the Internet of Things / Utku Kose -- Perceived Threat Modeling for Cyber-Physical Systems / Christopher Leberknight.
                    Subjects:   Internet of things Security measures. 
                                COMPUTERS Computer Literacy. 
                                COMPUTERS Computer Science. 
                                COMPUTERS Data Processing. 
                                COMPUTERS Hardware General. 
                                COMPUTERS Information Technology. 
                                COMPUTERS Machine Theory. 
                                COMPUTERS Reference. 
                    Summary: Presents an Cyber-Assurance approach to the Internet of Things (IoT) This book discusses the cyber-assurance needs of the IoT environment, highlighting key information assurance (IA) IoT issues and identifying the associated security implications. Through contributions from cyber-assurance, IA, information security and IoT industry practitioners and experts, the text covers fundamental and advanced concepts necessary to grasp current IA issues, challenges, and solutions for the IoT. The future trends in IoT infrastructures, architectures and applications are also examined. Other topics discussed include the IA protection of IoT systems and information being stored, processed or transmitted from unauthorized access or modification of machine-2-machine (M2M) devices, radio-frequency identification (RFID) networks, wireless sensor networks, smart grids, and supervisory control and data acquisition (SCADA) systems. The book also discusses IA measures necessary to detect, protect, and defend IoT information and networks/systems to ensure their availability, integrity, authentication, confidentially, and non-repudiation. . Discusses current research and emerging trends in IA theory, applications, architecture and information security in the IoT based on theoretical aspects and studies of practical applications. Aids readers in understanding how to design and build cyber-assurance into the IoT. Exposes engineers and designers to new strategies and emerging standards, and promotes active development of cyber-assurance. Covers challenging issues as well as potential solutions, encouraging discussion and debate amongst those in the field Cyber-Assurance for the Internet of Things is written for researchers and professionals working in the field of wireless technologies, information security architecture, and security system design. This book will also serve as a reference for professors and students involved in IA and IoT networking. 
                    Genre: Electronic books. 
                    Bibliography: Includes bibliographical references and index. 
                    Database: WorldCat
        </description>
        <formats>
            <nameformat>View all editions and formats</nameformat>
            <linkformat>https://ecu.on.worldcat.org/oclc/966445296#editions-panel966445296-section</linkformat>
        </formats>
        <source></source>
        <holder>
            <name>Edith Cowan University</name>
            <linkholder>https://ecu.on.worldcat.org/search?queryString=bn%3A1119193788</linkholder>
        </holder>
    </item>

这是我的xslt

    <?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>
    <head> 
        <title>Internet of Things</title>
        <link rel="stylesheet" type="text/css" href="workshop.css" />
    </head>
    <body>
        <h1>Internet of things</h1>
        <xsl:for-each select="items/item">
        <xsl:sort select="year" order="ascending"/>
            <div class="imgColumn">
                <img>
                    <xsl:attribute name="src">
                        <xsl:value-of select="thumbnail" />
                    </xsl:attribute>
                </img>
            </div>
            <div class="textColumn">
                <strong><a href="{link}"><xsl:value-of select="title" /></a><br /></strong>
                by <a href="{author/authorlink}"><xsl:value-of select="author/authorname" /></a><br />
                <xsl:value-of select="type" /> | <xsl:value-of select="year" /> | <a href="{formats/linkformat}"><xsl:value-of select="formats/nameformat" /></a><br />
                <xsl:value-of select="description" /><br />
                Source: <xsl:value-of select="source" /><br />
                Holder: <a href="{holder/linkholder}"><xsl:value-of select="holder/name" /></a><br />
            </div>
        </xsl:for-each>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

我是标记语言的新手,我期待着你的帮助。

2 个答案:

答案 0 :(得分:1)

您遇到空白问题。通常情况下,sequences of white space are collapsed into a single character,因此您显示的HTML文档不会包含XML文件中的换行符。

您可以使用div而不是PRE,或者您必须在XSLT中添加换行符,以便将description的内容分组为单独的元素。

答案 1 :(得分:1)

您的XML文档包含结构化和非结构化部分。我倾向于通过将自由文本描述解析为以下内容将其转换为完全结构化的形式:

<Publication>Hoboken, New Jersey : Wiley : IEEE Press, [2017]</Publication>
<Physical>1 online resource</Physical>
...
<Subjects>
  <Subject>Internet of things Security measures.</Subject>
  <SubjectsCOMPUTERS Computer Literacy.</Subject>
  ...
</Subjects>

完成后,您可以更加灵活地开始使用这些信息。

在XSLT 2.0中,解析并不困难。使用tokenize()将其分成几行;使用xsl:for-each-group在包含冒号的任何行上启动一个新组;为每个组创建一个新元素,如果该组包含多个行,则包含多个子元素。