XSLT の可能性についてもっと学ぶために、別のアプローチを使用してこの条件付きコードを記述するより良い方法があるかどうか疑問に思っています。
最初のインスタンスで href を検索するだけで、href 入力が存在する場合は、リンク付きの関連付けられた画像が表示され、alt タグの出力が表示されます。href 入力が存在しない場合、画像自体だけが + alt タグ出力として表示されます。
見た目も感じも少し不格好ですが、特定の目的には問題なく機能します。
そのため、結果を達成するためのよりクリーンでスマートな方法があるかどうかを知りたいと思っています。
アドバイスをいただければ幸いです。
ありがとう、オズモ
とにかく、これが私のマスターピースです...
<!-- SUPPORTING IMAGE HREF CONDITIONAL -->
<xsl:choose>
<xsl:when test="SupportingImageLink/a/@href !=''">
<tr>
<td>
<a href="{SupportingImageLink/a/@href}">
<img src="{SupportingImage/img/@src}" width="680" alt="{SupportingImage/img/@alt}" style="border: 0;width: 100%;max-width: 680px;" class="center-on-narrow"></img>
</a>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<img src="{SupportingImage/img/@src}" width="680" alt="{SupportingImage/img/@alt}" style="border: 0;width: 100%;max-width: 680px;" class="center-on-narrow"></img>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
<!-- SUPPORTING IMAGE HREF CONDITIONAL : END -->
ここで要求されているのは、XML を削除したものです...
<root>
<Title>New layout test</Title>
<Edition>Octovember 2019</Edition>
<Notification>
<Body>Warning Warning Warning Will Robinson!! Aliens Aliens Aliens everywhere!</Body>
</Notification>
<Introduction>
<Heading>Squids attack!</Heading>
<Body>Ugh tacos artisan, single-origin coffee jianbing hoodie skateboard. 90's unicorn next level fixie. Glossier coloring book drinking vinegar, health goth flexitarian activated charcoal yuccie hexagon whatever normcore bushwick ethical mustache plaid lyft. Chicharrones edison bulb vinyl disrupt tbh glossier, marfa mumblecore four loko +1 leggings.</Body>
</Introduction>
<Section>
<Heading>Just in - Cyborg bears attacking!</Heading>
<Structure>3</Structure>
<SupportingImage>
<img src="/uploadedImages/dev/robots.png?n=3082" alt="Will Robinson" title="Will Robinson" style="width: 680px; height: 283px;" align="left" width="680" height="283" />
</SupportingImage>
<SupportingImageLink>
<a href="http://www.squids-attack/cyb-bears.html">AAARRRRGGGGHHHH!!!</a>
</SupportingImageLink>
<Body>Ugh tacos artisan, single-origin coffee jianbing hoodie skateboard. 90's unicorn next level fixie. Glossier coloring book drinking vinegar, health goth flexitarian activated charcoal yuccie hexagon whatever normcore bushwick ethical mustache plaid lyft. Chicharrones edison bulb vinyl disrupt tbh glossier, marfa mumblecore four loko +1 leggings. Knausgaard af YOLO, direct trade drinking vinegar try-hard williamsburg roof party asymmetrical snackwave waistcoat. Venmo food truck next level raw denim, pabst photo booth quinoa chambray art party hot chicken cliche tote bag polaroid direct trade whatever. Shabby chic lomo locavore slow-carb leggings.</Body>
<Button>More information</Button>
</Section>
</root>