2017-11-06 4 views
0

안녕하세요, 저는 xml/xsl을 처음 접했습니다. 내가, 내가 (작업) XSL 코드 다음 한 테이블에서 보여 XML 코드를XSLT 이드 바꾸기, 다른 노드의 값 가져 오기

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="Miau.xsl"?> 
<export xmlns="urn:VocabularyExport"> 

<categories> 
    <category name="A" id="123" /> 
    <category name="B" id="456" /> 
</categories> 

<vocables> 
    <vocable categoryId="123" spanishWord="uno" engWord="one" id="45d0a344-785b- 
4463-9877-5474c99fdc74" /> 
    <vocable categoryId="456" spanishWord="dos" engWord="two" id="03efffbb-1cbf- 
44f9-a377-74da252daac0" /> 
</vocables> 
</export> 

다음 한 대신 내가 카테고리 이름으로 대체 할 categoryId

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:l="urn:VocabularyExport"> 

<xsl:key name="category" match="category" use="@id" /> 
<xsl:template match="/"> 
<html> 
    <body> 

    <h1>My Vocable Colletion</h1> 
    <table border="1"> 
     <tr bgcolor="#9acd32"> 
     <th>Id</th> 
     <th>Deutsches Wort</th> 
     <th>Spanishes Wort</th> 
     <th>CategoryId</th> 
     </tr> 
     <xsl:for-each select="l:export/l:vocables/l:vocable"> 
     <tr> 
      <td> 
      <xsl:value-of select="@id"/> 
      </td> 
      <td> 
      <xsl:value-of select="@germanWord"/> 
      </td> 
      <td> 
      <xsl:value-of select="@spanishWord"/> 
      </td> 
      <td> 
      <xsl:value-of select="@categoryId"/> 
      </td> 
     </tr> 
     </xsl:for-each> 
     </table> 
    </body> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 

(참조 노드 categories). 제안이 있습니까?

답변

0

XSLT에서 네임 스페이스를 처리 할 때 추가 한 것처럼 XML/XSLT를 처음 사용하는 사람에게 좋은 출발을 만들었습니다. 그러나, 당신은 당신의 열쇠에 이것을 놓쳤습니다. 그것은,이

<xsl:key name="category" match="l:category" use="@id" /> 

해야 카테고리 이름을 얻기 위해, 당신이 원하는 표현은 이것이다 :

<xsl:value-of select="key('category', @categoryId)/@name"/> 
+0

아, 젠장 난 이미 거의 같은 시도했지만 내 "일치"거짓 : D 유 대단히 고맙다;) – Trace