为了更多地了解 XSLT 的可能性,我想知道这是否是使用不同方法编写此条件代码的更好方法。
它只是在第一个实例中查找 href,如果存在 href 输入,则带有链接的关联图像将显示 + alt 标签输出。如果不存在 href 输入,则仅图像本身将显示 + alt 标签输出。
它适用于特定目的,尽管看起来和感觉有点笨重。
所以我想知道是否有更清洁或更智能的方式来实现结果。
任何建议将不胜感激。
谢谢,奥兹莫
Anyhoo,这是我的杰作……
<!-- 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>