0

xsl:apply テンプレート要素にテストを追加しようとしましたが、「式がノード セットに評価されません」というエラーが表示され続けます。誰かが私が間違っていることを指摘して、私を正しい方向に向けることができるかどうか疑問に思っています.

ここに私のXMLがあります

<?xml version="1.0" encoding="utf-8"?>
<catalog>
<cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
        <band>
            <guitar>Joe</guitar>
            <drums>Rachel</drums>
            <bass>Mike</bass>
        </band>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
</cd>
<cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
        <band>
            <guitar>Cat</guitar>
            <drums>Paul</drums>
            <bass>Bobby</bass>
        </band>     
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
</cd>
<cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
        <band>
            <guitar>Eric</guitar>
            <drums>Bill</drums>
            <bass>Jason</bass>
        </band>     
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
</cd>
</catalog>

ここに私のXSLTがあります:

<?xml version="1.0" encoding="utf-8"?>
<!-- DWXMLSource="Catalog.xml" -->
<!DOCTYPE xsl:stylesheet  [
<!ENTITY nbsp   "&#160;">
<!ENTITY copy   "&#169;">
<!ENTITY reg    "&#174;">
<!ENTITY trade  "&#8482;">
<!ENTITY mdash  "&#8212;">
<!ENTITY ldquo  "&#8220;">
<!ENTITY rdquo  "&#8221;"> 
<!ENTITY pound  "&#163;">
<!ENTITY yen    "&#165;">
<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="utf-8"/>

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="catalog">
<xsl:apply-templates select="cd" />
</xsl:template>

<xsl:template match="cd">
  <p style="color:red;">
    <xsl:apply-templates select="title = 'Empire Burlesque'" />
  </p>
  <p style="color:blue;">
    <xsl:apply-templates select="artist = 'Bob Dylan'" />
  </p>
  <p style="color:green;">
    <xsl:apply-templates select="band/guitar = 'Joe'" />
  </p>
</xsl:template>

<xsl:template match="title">
Title: <xsl:apply-templates />    
</xsl:template>


<xsl:template match="artist">
Artist: <xsl:apply-templates />   
</xsl:template>

<xsl:template match="band/guitar">
Guitar: <xsl:apply-templates />   
</xsl:template>

</xsl:stylesheet>

私が期待していた結果は次のとおりです。

Title: Empire Burlesque

Artist: Bob Dylan

Guitar: Joe
4

2 に答える 2

1

条件は以下の方法で作成されます。

<xsl:template match="cd">
  <p style="color:red;">
    <xsl:apply-templates select="title[text()='Empire Burlesque']" />
  </p>
  <p style="color:blue;">
    <xsl:apply-templates select="artist[text()='Bob Dylan']" />
  </p>
  <p style="color:green;">
    <xsl:apply-templates select="band/guitar[text()='Joe']" />
  </p>
</xsl:template>
于 2013-07-02T02:21:27.207 に答える