2011-03-16 2 views
0

나는 다음과 같은 XSLT 질문이 있습니다XSLT 일치 문제

은 가정하자 내가 가진이 XML

<items> 
    <item> 
     <type>dog</type> 
     <color>brown</color> 
    </item> 
    <item> 
     <type>dog</type> 
     <color>brown</color> 
    </item> 
    <item> 
     <type/> 
     <color>none</color> 
    </item> 
    <item> 
     <type>dog</type> 
     <color>black</color> 
    </item> 
</items> 

나는 XSL 1.0에서 다음을 사용하는 경우가 :

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="item[type='dog']"> 
     <item> 
      <itemType><xsl:value-of select="type"/></itemType> 
      <itemColor><xsl:value-of select="color"/></itemColor> 
     </item> 
    </xsl:template> 

</xsl:stylesheet> 

그것은에만 표시됩니다를 빈 노드 앞에 먼저 일치합니다.

내가 간과할만한 것이 있습니까?

+5

더 이상의 문맥이 없으면 대답 할 수 없습니다. 샘플에 따르면 서식 파일은 위치에 관계없이 "dog"유형의 모든 항목과 일치합니다. 당신이 언급하지 않은 다른 것이 있어야합니다. – Tomalak

+1

Aja! [내장 템플릿 규칙] (http://www.w3.org/TR/xslt#built-in-rule) 때문에이 질문을 했습니까? 빈'type' 자식을 가진'item' 또한 내장 된 "any element"규칙에 의해 일치 될 것입니다 –

+0

"내가 간과하고있는 것이 있습니까?" - 예. 불행히도 우리는 무엇을 모릅니다. 문제는 당신이 우리에게 보여주지 않은 코드에 있습니다. –

답변

1

IE8에서 test.xml을로드하면 간단한 예제가 작동합니다. 도움이되지 않습니다, 당신의 문제에 대한 자세한 정보와 질문을 수정하십시오 나는 test.xsl

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
    <html> 
    <head> 
     <title>Title</title> 
    </head> 
    <body> 
     <xsl:apply-templates /> 
    </body> 
    </html> 
</xsl:template> 
<xsl:template match="item"/> <!-- default item match (prints nothing) --> 
<xsl:template match="item[type='dog']"> 
    <xsl:value-of select="."/> 
</xsl:template> 
</xsl:stylesheet> 

로 출력 dog dog dog

저장이

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<?xml-stylesheet type="text/xsl" href="test.xsl"?> 
<items> 
    <item> 
     <type>dog</type> 
    </item> 
    <item> 
     <type>dog</type> 
    </item> 
    <item> 
     <type>cat</type> 
    </item> 
    <item> 
     <type>dog</type> 
    </item> 
</items> 

text.xml로 저장이를 얻을.

+0

고맙습니다. 이것은 효과가 있었다. – jexx2345