2012-01-13 16 views
0

XMLを2つ出力するxslファイルを作成しました。外部XMLファイルからの出力

xmlのうちの1つは、1回だけ刈り取られます。その唯一の構造とその作業以来、私はそのコードを投稿しませんので、 しかし、他の私はツリー構造全体を出力したいです。しかし、それは最初のものだけを印刷します。木全体ではありません。

これは、病気は、現時点でまで来る何

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 

<html> 
<body> 


<xsl:for-each select="$doc1//quiz//question"> 
<xsl:value-of select="$doc1//author" /> 
<br /> 
<xsl:value-of select="$doc1//questionText" /> 
<br /> 
<xsl:text>Ger </xsl:text><xsl:value-of select="$doc1//points" /><xsl:text> Poäng </xsl:text> 
</xsl:for-each> 

</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

おかげ

編集です:あなたの問題は、あなたがorigionalに戻って参照され ウィル広告私のXMLファイル

<?xml version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet type="text/xsl" href="q2.xsl"?> 
<quiz> 
<question> 
<author>Författare 1</author> 
<questionText>Fråga 1</questionText> 
<correct>Svar 1</correct> 
<incorrect>fel 1</incorrect> 
<incorrect>fel 1-2</incorrect> 
<points>1</points> 
</question> 

<question> 
<author>Författare 2</author> 
<questionText>Fråga 2</questionText> 
<correct>Svar 2</correct> 
<incorrect>fel 2</incorrect> 
<incorrect>fel 2-3</incorrect> 
<points>2</points> 
</question> 

<question> 
<author>Författare 3</author> 
<questionText>Fråga 3</questionText> 
<correct>Svar 3</correct> 
<incorrect>fel 3</incorrect> 
<incorrect>fel 3-4</incorrect> 
<points>3</points> 
</question> 

<question> 
<author>Författare 4</author> 
<questionText>Fråga 4</questionText> 
<correct>Svar 4</correct> 
<incorrect>fel 4</incorrect> 
<incorrect>fel 4-5</incorrect> 
<points>4</points> 
</question> 

<question> 
<author>Författare 5</author>+ 
<questionText>Fråga 5</questionText> 
<correct>Svar 5</correct> 
<incorrect>fel 5</incorrect> 
<incorrect>fel 5-6</incorrect> 
<points>5</points> 
</question> 

</quiz> 
+0

xmlを追加して解決策を提供する方が簡単かもしれません。 – Treemonkey

答えて

2

for-eachステートメント

を入力すると、実際のコンテキストノードの代わりに $docが表示されます。

これは、テンプレートを適用使っ

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 

<html> 
<body> 


<xsl:for-each select="$doc1/quiz/question"> 
<xsl:value-of select="author" /> 
<br /> 
<xsl:value-of select="questionText" /> 
<br /> 
<xsl:text>Ger </xsl:text><xsl:value-of select="points" /><xsl:text> Poäng </xsl:text> 
</xsl:for-each> 

</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

エクストラ例を動作するはずです!

これは、ectを読むのにはるかに優れています。いったん複雑になると、ノードセットのコンテキストに簡単に気づくことができます!

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/">  
     <html> 
      <body> 
       <xsl:apply-templates select="$doc1/quiz/question"/> 
      </body> 
     </html> 
    </xsl:template> 

    <xsl:template match="question"> 
     <xsl:value-of select="author" /> 
     <br /> 
     <xsl:value-of select="questionText" /> 
     <br /> 
     <xsl:text>Ger </xsl:text> 
     <xsl:value-of select="points" /> 
     <xsl:text> Poäng </xsl:text> 
    </xsl:template> 
</xsl:stylesheet> 
+0

おお、私は、これでほぼ1時間苦労してくれてあります:) – kakka47

+0

あなたの歓迎ではなく、apply-templates match = "blah"を使用して一致する新しいテンプレートを作成します。例を追加します – Treemonkey

+0

ちょうどそれを試し始めた:) ありがとう:) – kakka47

関連する問題