需要解析TEI-XML文件中的一些数据-php或xsl(以及如何解析?)
我的站点上有许多XMLTEI文件,当可视化它们时,我希望在信息框中显示文档的一些元信息。 我在PHP方面非常有限,所以我首先考虑用XSL对XML进行预处理,但到目前为止,我未能重新安排输出中项目的顺序。由于xml文件在服务器上,所以我决定搜索有关在PHP中解析xml的教程。但是教程总是使用非常有限的XML文件,我无法概括规则。所以我还是不确定该走哪条路 我正在发布一个文件的标题部分,其中包含所需的信息,下面是我设想的输出需要解析TEI-XML文件中的一些数据-php或xsl(以及如何解析?),php,xml,xslt,xml-parsing,Php,Xml,Xslt,Xml Parsing,我的站点上有许多XMLTEI文件,当可视化它们时,我希望在信息框中显示文档的一些元信息。 我在PHP方面非常有限,所以我首先考虑用XSL对XML进行预处理,但到目前为止,我未能重新安排输出中项目的顺序。由于xml文件在服务器上,所以我决定搜索有关在PHP中解析xml的教程。但是教程总是使用非常有限的XML文件,我无法概括规则。所以我还是不确定该走哪条路 我正在发布一个文件的标题部分,其中包含所需的信息,下面是我设想的输出 <TEI xmlns="http://www.tei-c.o
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="ahne1539">
<teiHeader>
<fileDesc>
<titleStmt>
<title level="s">Edición digital</title>
<title type="main" level="a">Cristóbal Márquez a su madre. <lb/>Guatemala. 2 de
enero de 1813</title>
<editor>
<persName>Werner Stangl </persName>
</editor>
</titleStmt>
<publicationStmt>
<date when="2013">2013</date>
</publicationStmt>
<sourceDesc>
<msDesc>
<msIdentifier>
<country>España</country>
<settlement>Madrid</settlement>
<repository>Archivo Histórico Nacional</repository>
<idno>Estado 1539,doc.3</idno>
</msIdentifier>
<physDesc>
<objectDesc>
<supportDesc>
<extent> 1 folio, r-v, y un sobre</extent>
</supportDesc>
<layoutDesc>
<p> Orientación horizontal, doblada</p>
</layoutDesc>
</objectDesc>
<handDesc hands="1">
<p> Letra algo gruesa, regularmente legible</p>
</handDesc>
</physDesc>
</msDesc>
</sourceDesc>
</fileDesc>
<encodingDesc>
[...]
</encodingDesc>
<profileDesc>
<langUsage>
<language ident="es" usage="90">español</language>
<language ident="ca" usage="10">catalán</language>
</langUsage>
</profileDesc>
</teiHeader>
所需输出为
<h1>[tei:title with type="main"]</h1>
<h2>[tei:repository], [tei:idno]</h2>
<p>Editado por [tei:editor]</p>
<p>Extensión: [tei:extent]</p>
<p>Plano: [tei:layoutDesc]</p>
<p>Letra: [handDesc]</p>
<p>Lengua: [value of @usage]% [tei:language]</p>
在最后一行中,实际上应同时显示加泰罗尼亚语和西班牙语条目。尝试将此作为起点:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="tei">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="tei:TEI/tei:teiHeader/tei:fileDesc">
<h1>
<xsl:value-of select="tei:titleStmt/tei:title[@type='main']"/>
</h1>
<h2>
<xsl:value-of select="tei:sourceDesc/tei:msDesc/tei:msIdentifier/tei:repository"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="tei:sourceDesc/tei:msDesc/tei:msIdentifier/tei:idno"/>
</h2>
<!-- KEEP WORKING ON IT -->
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
多谢各位。这是我的新代码,它实现了我想要的
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="tei">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Metadata</title></head>
<body>
<xsl:for-each select="tei:TEI/tei:teiHeader">
<h1>
<xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:title[@type='main']"/>
</h1>
<h2>
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:msIdentifier/tei:repository"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:msIdentifier/tei:idno"/>
</h2>
<p>
Editado por <xsl:value-of select="tei:fileDesc/tei:titleStmt/tei:editor"/>
</p>
<hr/>
<p>
Dimensión: <xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:objectDesc/tei:supportDesc/tei:extent"/>
</p>
Diseño: <xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:objectDesc/tei:layoutDesc/tei:p"/>
<p>
<xsl:if test="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:handDesc/@hands=1">Letra: <xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:handDesc"/></xsl:if><xsl:if test="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:handDesc/@hands>1"><xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:handDesc/@hands"/> letras: <xsl:value-of select="tei:fileDesc/tei:sourceDesc/tei:msDesc/tei:physDesc/tei:handDesc"/>
</xsl:if>
</p>
<p>Lengua(s):
<xsl:for-each select="tei:profileDesc/tei:langUsage/tei:language">
<xsl:value-of select="@usage"/>% <xsl:value-of select="."/>
</xsl:for-each>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
您的任务似乎是XSLT命中注定的,因此目前我将坚持使用这种方法。您能向我们展示您迄今为止尝试过的任何代码(例如XSLT)吗?谢谢。正如你在我自己的回答中所看到的,你让我走上了正确的道路!现在,这是关于实施的,如果你能在这方面也帮我,或者我会问一个新问题。我需要在我的站点上包含原始xml,动态添加样式表并显示它。即使我将样式表编码为XML并将其包含在php中,它也会被忽略,并显示整个文件。