我有一个源XML文件,需要一个模板来提取嵌套元素。
在此示例中:
<?xml version="1.0" encoding="UTF-8"?>
<jhove xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://hul.harvard.edu/ois/xml/ns/jhove" xsi:schemaLocation="http://hul.harvard.edu/ois/xml/ns/jhove http://hul.harvard.edu/ois/xml/xsd/jhove/1.6/jhove.xsd" name="Jhove" release="1.20.1" date="2018-03-29">
<date>2019-10-29T16:30:24+01:00</date>
<repInfo uri="h:%5CEnviar%5Cpreservacion%5Cfvr_a45_002%5Cmets%5Cfvr_a45_002.xml">
<reportingModule release="1.4" date="2007-01-08">XML-hul</reportingModule>
<lastModified>2019-10-29T16:30:24+01:00</lastModified>
<size>64169</size>
<format>XML</format>
<version>1.0</version>
<status>Well-Formed and valid</status>
<sigMatch>
<module>XML-hul</module>
</sigMatch>
<mimeType>text/xml</mimeType>
<properties>
<property>
<name>XMLMetadata</name>
<values arity="List" type="Property">
<property>
<name>Parser</name>
<values arity="Scalar" type="String">
<value>com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser</value>
</values>
</property>
<property>
<name>Encoding</name>
<values arity="Scalar" type="String">
<value>UTF-8</value>
</values>
</property>
<property>
<name>Schemas</name>
<values arity="List" type="Property">
<property>
<name>Schema</name>
<values arity="Array" type="Property">
<property>
<name>NamespaceURI</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/METS/</value>
</values>
</property>
<property>
<name>SchemaLocation</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/mix/v20 http://www.loc.gov/standards/mix/mix20/mix20.xsd http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/premis.xsd http://cosimo.stanford.edu/sdr/metsrights/ http://www.loc.gov/standards/rights/METSRights.xsd http://ead3.archivists.org/schema/ https://www.loc.gov/ead/ead3.xsd</value>
</values>
</property>
</values>
</property>
<property>
<name>Schema</name>
<values arity="Array" type="Property">
<property>
<name>NamespaceURI</name>
<values arity="Scalar" type="String">
<value>http://ead3.archivists.org/schema/</value>
</values>
</property>
</values>
</property>
<property>
<name>Schema</name>
<values arity="Array" type="Property">
<property>
<name>NamespaceURI</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/premis/v3</value>
</values>
</property>
</values>
</property>
<property>
<name>Schema</name>
<values arity="Array" type="Property">
<property>
<name>NamespaceURI</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/mix/v20</value>
</values>
</property>
</values>
</property>
<property>
<name>Schema</name>
<values arity="Array" type="Property">
<property>
<name>NamespaceURI</name>
<values arity="Scalar" type="String">
<value>http://cosimo.stanford.edu/sdr/metsrights/</value>
</values>
</property>
</values>
</property>
</values>
</property>
<property>
<name>Root</name>
<values arity="Scalar" type="String">
<value>mets:mets</value>
</values>
</property>
<property>
<name>Namespaces</name>
<values arity="List" type="Property">
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>premis</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/premis/v3</value>
</values>
</property>
</values>
</property>
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>rts</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://cosimo.stanford.edu/sdr/metsrights/</value>
</values>
</property>
</values>
</property>
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>mets</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/METS/</value>
</values>
</property>
</values>
</property>
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>ead</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://ead3.archivists.org/schema/</value>
</values>
</property>
</values>
</property>
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>mix</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://www.loc.gov/mix/v20</value>
</values>
</property>
</values>
</property>
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>xsi</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://www.w3.org/2001/XMLSchema-instance</value>
</values>
</property>
</values>
</property>
<property>
<name>Namespace</name>
<values arity="Array" type="Property">
<property>
<name>Prefix</name>
<values arity="Scalar" type="String">
<value>xlink</value>
</values>
</property>
<property>
<name>URI</name>
<values arity="Scalar" type="String">
<value>http://www.w3.org/1999/xlink</value>
</values>
</property>
</values>
</property>
</values>
</property>
<property>
<name>Comments</name>
<values arity="List" type="String">
<value>DMD-EAD Global para a organización</value>
<value>NIVEL FONDS - Equivalencia con FONDO</value>
<value>NIVEL 01 - RECORDGRP - Equivalencia con SECCION</value>
<value>NIVEL 02 - SERIES - Equivalencia con serie</value>
<value>NIVEL 03 - FICHEIRO - Equivalencia con UNIDADE DOCUMENTAL</value>
<value>FICHEIROS...............................................................</value>
<value>Ficheiros de ARQUIVO en TIF</value>
<value>Ficheiro de referencia en JPG</value>
<value>Ficheiros de miniaturas</value>
<value>Ficheiros de ocr</value>
<value>Ficheiro de referencia en PDF</value>
<value>MAPA ESTRUCTURAL</value>
<value>¿FICHEIRO DE RESUME EN PDF?</value>
</values>
</property>
</values>
</property>
</properties>
</repInfo>
</jhove>
我只需要提取值:
格式正确且有效
我在模板中尝试了很多东西,但是没有结果。
我的(无效)模板:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="/jhove/repInfo">
<datos LABEL="{uri}"></datos>
<nome uri="{/jhove/repInfo/uri}"> </nome>
<ficheiro>
<xsl:value-of select="status"/>
</ficheiro>
<size>
<xsl:value-of select="lastModified"/>
</size>
<size>
</size>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我还读了很多有关空名称空间的内容,等等,但是我只能获取and字段的值。
任何灵感都会受到欢迎。
非常感谢。