问题
I am new to coding. Started XSL coding from past 1 month. I want to creat a hyperlink according to the item_id. But my concat is not working as desired.
My requirement is that i have to get create hyperlinks based on the variable item_id For example: https://xyz.com/webpr/webpr.php?objtype=frames&g_startlink=maintain&g_startdata=194970&g_userid=msbzzh&g_session_id=6017650`
https://xyz.com/webpr/webpr.php?objtype=frames&g_startlink=maintain&g_startdata=194971&g_userid=msbzzh&g_session_id=6017650
where the variable item_id comes inbetween the link. (194970, 194971 and so on)
So here is my code:
<xsl:when test ="$propName ='item_id'">
<td>
<xsl:variable name="itemId" select="$occRef/@*[local-name()=$propName]" />
<a href = "{concat('https://xyz.com/webpr/webpr.php?objtype=frames&g_startlink=maintain&g_startdata=','<xsl:value-of select="$itemId"/>','&g_userid=msbzzh&g_session_id=6017650')}" target="_blank"> <xsl:value-of select="$itemId" /></a>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</td>
</xsl:when>
and i also tried like this.. But both of them didn't work out.
<a href = "{concat('https://xyz.com/webpr/webpr.php?objtype=frames&g_startlink=maintain&g_startdata=','$itemId','&g_userid=msbzzh&g_session_id=6017650')}" target="_blank"> <xsl:value-of select="$itemId" /></a>
回答1:
UPDATED: You forgot to escape ampersands and indeed the variable was used incorrectly. See below the correct syntax.
<xsl:when test="$propName='item_id'">
<td>
<xsl:variable name="itemId" select="$occRef/@*[local-name()=$propName]"/>
<a href="{concat('https://xyz.com/webpr/webpr.php?objtype=frames&g_startlink=maintain&g_startdata=', $itemId, '&g_userid=msbzzh&g_session_id=6017650')}" target="_blank">
<xsl:value-of select="$itemId"/>
</a>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</td>
</xsl:when>
来源:https://stackoverflow.com/questions/25807482/xsl-stylesheet-creating-hyperlink-based-of-query-item-id