機能する XSLT 条件を設定するには、助けが必要です。質問ノードを実行する for-each ループ内。ノード A の条件が機能する場合、ノード B に詳細を表示します。XML の例:
<Survey>
<questions>
<Number>1.0</Number>
<Question>Was the show good?</Question>
<Answer>Yes/No</Answer>
<Details>N/A</Details>
</questions>
<questions>
<Number>1.1</Number>
<Question>Explain why</Question>
<Answer>N/A</Answer>
<Details>The actors were good</Details>
</questions>
<questions>
<Number>2.0</Number>
<Question>Was the food good?</Question>
<Answer>Yes|No</Answer>
<Details>N/A</Details>
</questions>
<questions>
<Number>2.1</Number>
<Question>Provide details</Question>
<Answer>N/A</Answer>
<Details>The pasta was too salty</Details>
</questions>
</Survey>
必要なのは、for-each のループのみを使用することです 質問番号 = 1.0 および回答 = 'はい' の場合、質問番号 1.1 のみに詳細を表示します 質問番号 = 2.0 および回答 = 'いいえ' の場合、質問番号 2.1 に詳細を表示します
if, for each, choose/when など、あらゆる方法を試しましたが、うまくいきませんでした。他の投稿を確認しましたが、同様のものは見つかりませんでした。ツビさん、よろしくお願いします。
申し訳ありませんが、次のようにする必要があります。
<Survey>
<questions>
<Number>1.0</Number>
<Question>Was the show good?</Question>
<Answer>Yes</Answer>
<Details>N/A</Details>
</questions>
<questions>
<Number>1.1</Number>
<Question>Explain why</Question>
<Answer>N/A</Answer>
<Details>The actors were good</Details>
</questions>
<questions>
<Number>2.0</Number>
<Question>Was the food good?</Question>
<Answer>Yes</Answer>
<Details>N/A</Details>
</questions>
<questions>
<Number>2.1</Number>
<Question>Provide details</Question>
<Answer>N/A</Answer>
<Details>The pasta was too salty</Details>
</questions>
</Survey>
これが私のコードの一部です: (申し訳ありませんが、実際には他の誰かのコードです。前の質問に「はい」または「いいえ」と明確に回答されたときに次の質問を表示する部分を変更する必要があります
<fo:table-body start-indent="0pt">
<xsl:for-each select="../Survey">
<xsl:for-each select="questions">
<xsl:sort select="Number" data-type="number" order="ascending"/>
<fo:table-row>
<xsl:choose>
<xsl:when test="ends-with(Number,'0')">
<fo:table-cell border="solid 1pt gray" padding="1pt" display-align="center">
<fo:block text-align="right">
<xsl:for-each select="Number"> ...
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1pt gray" padding="1pt" display-align="center">
<fo:block text-align="left">
<xsl:for-each select="Description"> ...
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1pt gray" padding="1pt" display-align="center">
<fo:block text-align="left" color="blue">
<xsl:for-each select="Answer"> ...
</xsl:for-each>
</fo:block>
</fo:table-cell> </xsl:when>
<xsl:when test="Number='1.1'">
<xsl:if test="//questions/Number='1.0' and //questions/Answer='No'">
<fo:table-cell border="solid 1pt gray" padding="1pt" display-align="center">
<fo:block text-align="right">
<xsl:for-each select="Number"> ...
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1pt gray" padding="1pt" display-align="center">
<fo:block text-align="left">
<xsl:for-each select="Question"> .....
</xsl:for-each>
</fo:block>
</fo:table-cell>
<fo:table-cell border="solid 1pt gray" padding="1pt" display-align="center">
<fo:block text-align="left" color="blue"> ....
<xsl:for-each select="Details">
</xsl:for-each>
</fo:block>
</fo:table-cell> </xsl:if>
</xsl:when>
<xsl:otherwise>do something</xsl:otherwise> </xsl:choose>
</fo:table-row>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</fo:table-body>