[英]using XSLT choose when on XML element not working
I am trying to format my Table so that there is a left padding, I would like the decision to happen inside my for statment as there are multiple rows which need the padding defined. 我正在尝试格式化我的表,以便有一个左边填充,我希望决定发生在我的for statment中,因为有多行需要定义填充。
I have created a XML element that tells me what padding to use so all I need to do is read this, however when ever I try to read it it dosnt show anything when i open the xml in my browser. 我已经创建了一个XML元素,告诉我要使用什么填充,所以我需要做的就是读取它,但是当我尝试读取它时,dosnt显示任何东西,当我在浏览器中打开xml时。
This is a sample of my xml. 这是我的xml示例。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="xmlstylesheet.xsl" type="text/xsl"?>
<Collection>
<Passives>
<Talent>Tra</Talent>
<TCost>1</TCost>
<Type>ANY</Type>
<Action>Pass</Action>
</Passives>
<Passives>
<Talent>Gen</Talent>
<TCost>1</TCost>
<Type>ANY</Type>
<Indent>1</Indent>
<Action>Pass</Action>
</Passives>
<Passives>
<Talent>Weap</Talent>
<TCost>12</TCost>
<Type>ANY</Type>
<Indent>2</Indent>
<Action>Pass</Action>
</Passives>
</Collection>
The gist of it is if there is no <Indent></Indent>
then padding should equal 15px if there is no Indent element, if indenet=1 then padding should equal 30 and finally indent = 2 then padding should equal 45. 它的要点是如果没有<Indent></Indent>
那么如果没有Indent元素,填充应该等于15px,如果indenet = 1则填充应该等于30,最后indent = 2然后填充应该等于45。
I am trying to define the padding inside my xslt for statment for Passives. 我试图在我的xslt中定义填充以获取Passive的声明。
<xsl:for-each select="Passives">
<div style="font-family:Calibri, Arial; font-size:5pt; cursor: default;">
<xsl:choose>
<xsl:when test="Indent == '2'">
<xsl:variable name="newpadding">45px</xsl:variable>
</xsl:when>
<xsl:when test="Indent == '1'">
<xsl:variable name="newpadding">30px</xsl:variable>
</xsl:when>
<xsl:when test="Indent != ''">
<xsl:variable name="newpadding">15px</xsl:variable>
</xsl:when>
</xsl:choose>
<xsl:if test="Talent != ''">
//etc
So as soon as I enter my for statment I would like to define newpadding so I an then apply it to my table padding later. 所以,一旦我输入我的for statment,我想定义newpadding,然后我再将它应用到我的表填充。
any help would be greatly appreciated. 任何帮助将不胜感激。
Instead of this: 而不是这个:
<xsl:choose>
<xsl:when test="Indent == '2'">
<xsl:variable name="newpadding">45px</xsl:variable>
</xsl:when>
<xsl:when test="Indent == '1'">
<xsl:variable name="newpadding">30px</xsl:variable>
</xsl:when>
<xsl:when test="Indent != ''">
<xsl:variable name="newpadding">15px</xsl:variable>
</xsl:when>
</xsl:choose>
Try this: 尝试这个:
<xsl:variable name="newpadding"
select="15 * (1 + concat(0, Indent))" />
You've only shown us a small portion of your XSLT, so there's no way to see if there are other issues that need fixing. 您只向我们展示了XSLT的一小部分,因此无法确定是否还有其他需要修复的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.