[英]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.