-
-
Save bmix/aef6d958f112114483a98515d60b28a9 to your computer and use it in GitHub Desktop.
XSLT 1.0 xsl:choose vs. XPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$a | self::node()[$a] | |
can stay for: | |
<xsl:choose> | |
<xsl:when test="$a"> | |
<xsl:value-of select="$a"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="."/> | |
</xsl:otherwise> | |
</xsl:choose> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output indent="yes"/> | |
<xsl:variable name="vinyl" select="document('test_i2.xml')"/> | |
<xsl:template match="node()|@*"> | |
<xsl:copy> | |
<xsl:apply-templates select="node()|@*"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- xsl:choose | |
<xsl:template match="@vinyl"> | |
<xsl:attribute name="vinyl"> | |
<xsl:variable name="test" select=" | |
$vinyl/Vinyl/Album[Title=current()/../@Title]/Vinyl"/> | |
<xsl:choose> | |
<xsl:when test="$test"> | |
<xsl:value-of select="$test"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="."/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:attribute> | |
</xsl:template> | |
--> | |
<!-- XPath | |
<xsl:template match="@vinyl"> | |
<xsl:attribute name="vinyl"> | |
<xsl:value-of select=" | |
$vinyl/Vinyl/Album[Title=current()/../@Title]/Vinyl | |
| | |
self::node()[count($vinyl/Vinyl/Album[Title=current()/../@Title])=0]"/> | |
</xsl:attribute> | |
</xsl:template> | |
--> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment