2014-02-27 61 views
0

我有这样的XMLXSL转换 - 选择节点ID通过字符串内容

<mets:mets xmlns:mets="http://www.loc.gov/METS/"> 
    <mets:fileSec> 
    <mets:fileGrp ID="REP1"> 
     <mets:file ID="FL1"> 
     <mets:FLocat LOCTYPE="URL" xlin:href="1.jpg" xmlns:xlin="http://www.w3.org/1999/xlink"/> 
     </mets:file> 
    </mets:fileGrp> 
    <mets:fileGrp ID="REP2"> 
     <mets:file ID="FL2"> 
     <mets:FLocat LOCTYPE="URL" xlin:href="1.tif" xmlns:xlin="http://www.w3.org/1999/xlink"/> 
     </mets:file> 
    </mets:fileGrp> 
    <mets:fileGrp ID="REP3"> 
     <mets:file ID="FL3"> 
     <mets:FLocat LOCTYPE="URL" xlin:href="2.jpg" xmlns:xlin="http://www.w3.org/1999/xlink"/> 
     </mets:file> 
    </mets:fileGrp> 
    </mets:fileSec> 
</mets:mets> 

我想作为输出的ID以JPG extention只有文件 - > FL1,FL3。

我有我的XSL文件的问题:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:mets="http://www.loc.gov/METS/" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:mods="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd" 
    exclude-result-prefixes="xlin"> 
    <xsl:output method="html" omit-xml-declaration="yes" indent="yes" /> 

    <xsl:template match="/"> 
     <xsl:for-each select="//mets:fileSec/mets:fileGrp/mets:file"> 
      <xsl:variable name="currentID" select="@ID" /> 
      <xsl:for-each select="//mets:fileSec/mets:fileGrp/mets:file/mets:FLocat"> 
       <xsl:variable name="testVariable" select="@xlink:href" xmlns:xlink="http://www.w3.org/1999/xlink" /> 
       <xsl:choose> 
        <xsl:when test="contains($testVariable, '.jpg')"><xsl:value-of select="$currentID"/>,</xsl:when> 
       </xsl:choose> 
      </xsl:for-each> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

但经过改造,我得到错误的输出为:FL1,FL1,FL2,FL2,FL3,FL3,

请帮我XSL 。 谢谢!

回答

2

会是这样的工作吗?

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:mets="http://www.loc.gov/METS/" 
xmlns:xlin="http://www.w3.org/1999/xlink"> 
<xsl:output method="text" encoding="UTF-8"/> 

<xsl:template match="/"> 
    <xsl:for-each select="mets:mets/mets:fileSec/mets:fileGrp/mets:file[contains(mets:FLocat/@xlin:href, '.jpg')]"> 
     <xsl:value-of select="@ID"/> 
     <xsl:if test="position()!=last()"> 
      <xsl:text>, </xsl:text> 
     </xsl:if> 
    </xsl:for-each> 
</xsl:template> 

</xsl:stylesheet> 
+0

非常感谢,这正是我所期待的! – prilia