简体   繁体   English

如何修复XSLT,使其如图所示显示XML?

[英]How can I fix my XSLT so that it displays my XML as pictured?

I'm new to XML and hoping for a little feedback. 我是XML的新手,希望能得到一些反馈。 I am trying to display my XML so that it looks like this: 我试图显示我的XML,使其看起来像这样:

How I hope to get my XML to display 我希望如何显示我的XML

I can't seem to get the elements to display in the templates. 我似乎无法让元素显示在模板中。 (Clearly, I am not building them correctly). (显然,我没有正确构建它们)。 How would I get the title element (Koha) to show up bold and larger as it does in the example? 我将如何获得标题元素(Koha),以使其与示例中的字体一样大胆和更大? I'm just feeling a bit stuck and my professor is busy and I was hoping someone might be able to offer suggestions about what to do next? 我只是有点卡住,我的教授很忙,我希望有人可以就下一步的工作提出建议。

my XML: 我的XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<digitalLibrarySystem xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:noNamespaceSchemaLocation="http://www.pages.drexel.edu/~eom25/657/diglibschema/digitalLibrarySystem.xsd">
<systemMetadata>
<title>Koha</title>
<creator>by Katipo Communications</creator>
<subject>public libraries</subject>
<subject>bibliographic managemen</subject>
<subject>distributed library systems</subject>
<description>Koha was one of the the first open-source Integrated Library Systems. It is used and maintained by the worldwide library community.</description>
<date>2000</date>
<type>ILS</type>
<rights>Open-source</rights>
<identifier xlink:type="simple" xlink:href="http://http://www.koha.org/">http://www.http://www.koha.org/</identifier>
</systemMetadata>
<aboutRecord>
<recordCreator>Matthew Weidemann</recordCreator>
<creationDate>May 6, 2018</creationDate>
</aboutRecord>

My XSLT so far: 到目前为止,我的XSLT:

 <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="/">
 <html>
 <body>
 <h1>"font-weight:bold"><xsl:value-of select="title"/></h1>
 <h2>by <xsl:value-of select="systemMetadata/creator"/></h2>
 <h3><xsl:value-of select="systemMetadata/subject"/></h3>
 <br/>
 <p>
 <h4><xsl:value-of select="systemMetadata/description"/></h4>
 <br/>
 </p>
  <h5><xsl:value-of select="systemMetadata/rights"/></h5>
  <br/>
  <h6><i>Record created by <xsl:value-of 
select="aboutRecord/recordCreator"/> on 
  <xsl:value-of select="aboutRecord/creationDate"/></i></h6>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

I am confused about the XPaths I think and Any suggestions are helpful. 我对我认为的XPath感到困惑,任何建议都是有帮助的。

I reorganized your XSLT file a little bit. 我对您的XSLT文件进行了一些重组。
You would have it a lot easier if you start to correctly indent the files. 如果您开始正确缩进文件,您会容易得多。
And have a look at the differences to begin to comprehend how XSLT works. 并查看其中的差异,以开始理解XSLT的工作方式。

So here is your (slightly modified) XSLT-1.0 file which brings you closer to your goal: 因此,这是您的(略作修改的)XSLT-1.0文件,它使您更接近目标:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!-- Create HTML header and stuff -->
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates />       <!-- Apply the other templates -->
            </body>
        </html>
    </xsl:template>

    <!-- Process all systemMetadata sub-nodes -->
    <xsl:template match="systemMetadata">                
        <h1>
            <b><xsl:value-of select="title"/></b>
        </h1>
        <h2>
            <xsl:value-of select="creator"/>
        </h2>
        <h2>
            <xsl:value-of select="subject"/>
        </h2>
        <br/>
        <p>
            <h3>
                <xsl:value-of select="description"/>
            </h3>
        </p>
        <h3>
            <xsl:value-of select="rights"/>
        </h3>
    </xsl:template>

    <!-- Process all aboutRecord sub-nodes -->
    <xsl:template match="aboutRecord">      
        <h3>
            <i>Record created by <xsl:value-of 
select="recordCreator"/> on <xsl:value-of select="creationDate"/></i>
        </h3>
    </xsl:template>

</xsl:stylesheet>

Now you can modify it to pretty print the results. 现在,您可以对其进行修改以漂亮地打印结果。
If you want to create the nice border, change the first template to 如果要创建漂亮的边框,请将第一个模板更改为

<!-- Create HTML header and stuff -->
<xsl:template match="/">
    <html>
        <body>
            <table border="1">
                <tr><td><xsl:apply-templates /></td></tr>
            </table>
        </body>
    </html>
</xsl:template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IE显示我的代码而不是我的网页,我该如何解决? - IE displays my code instead of my webpage, how can I fix this? 如何修复CSS,使其看起来正确? - How can I fix my CSS so it looks right? 如何将 Font Awesome 添加到我的项目中以正确显示图标? - How can I add the Font Awesome to my project so it displays the icons correctly? 我的代码没有执行获取、设置、发布,所以我的代码错误是什么,我该如何解决? - My codes are not doing get,set,post so what is my codes error how can i fix it? 如何计算XSLT的XML文件的段落并将其显示在HTML文件中? - How can I count paragraphs of my XML file and display them on the HTML file using XSLT? 如何使用 XSLT 编辑 XML 文件中的元素? - How to I use XSLT to edit elements in my XML file? 如何修复 li 元素的样式,使其显示在同一行上? - How can I fix the styling of my li element so it appears on same line? 我该如何修复我之前的代码,使其正常工作 - How can i fix my previous week code so it works properly 如何固定我的动画背景块的宽度和高度,以便我的数独方块输入和按钮仍然有效? - How can I fix the width and height of my animated background blocks, so that my sudoku square inputs and button still work? XSLT无法使用我的XML - XSLT not working with my XML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM