2017-09-15 50 views
1

所以,我的XML看起来是这样的:意外标记“[”在XSLT转换

<Document Resolution="{X=300,Y=300}"> 
    ... 
</Document> 

我试图生成与分辨率值的xml。它应该是这样的:

<image xdpi="300" ydpi="300"> 
    ... 
</image> 

现在,我的xslt文件看起来像这样(图像部分):

<image> 
    <xsl:attribute name="xdpi"> 
     <xsl:value-of select="/*/[substring-before(substring-after(@Resolution, 'X='), ',')]"/> 
    </xsl:attribute> 
    .... 
</image> 

我试图提取决议的X值。然而,这是我得到的消息:

在表达式中的异常标记“[”

我试着删除的方括号,但抱怨变得更糟。

有没有解决这个问题的方法?或另一种方式来提取分辨率值?

感谢

+1

为什么你想在所有使用方括号?你描述的情况没有意义。在任何情况下,谓词都不是完整的位置步骤 - IOW,在'['之前不能有'/'斜杠。 –

回答

2

只需使用

<xsl:template match="Document"> 
    <image xdpi="{substring-before(substring-after(@Resolution, 'X='), ',')}" ydpi="{...}">...</image> 
</xsl:template> 

对于你的方法,你需要

<xsl:value-of select="substring-before(substring-after(/*/@Resolution, 'X='), ',')"/>