需要使用 XSLT 从属性值中删除一些文本
Need to remove some text from attribute value using XSLT
我需要使用 XSLT 从属性值中删除一部分文本
XML 我用过:
<img imageid="47" alt="cup." height="300" width="400" class="right" src="https://tneb.com/Services/Gets/Contents/ucr-images-v1/Images/cup-36" />
我使用的 XSL:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all">
<xsl:template match="img">
<xsl:element name="image">
<xsl:attribute name="id">
<xsl:value-of select="@imageid"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@alt"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="@height"/>
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
<xsl:attribute name="align">
<xsl:value-of select="@class"/>
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="@src"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我得到的输出为:
<image id="47"
alt="cup."
height="300"
width="400"
align="right"
href="https://tneb.com/Services/Gets/Contents/ucr-images-v1/Images/cup-36"/>
预期输出必须是:
<image id="47"
alt="cup."
height="300"
width="400"
align="right"
href="/ucr-images-v1/Images/cup-36"/>
我需要从图像的属性值中删除一些文本。最后 3 只表示文件夹结构。所以我只需要它本身。
请给我任何建议。提前致谢。
要仅获取路径的最后 3 个位置步骤,请更改:
<xsl:value-of select="@src"/>
至:
<xsl:value-of select="tokenize(@src, '/')[position() gt last() - 3]" separator="/"/>
我需要使用 XSLT 从属性值中删除一部分文本
XML 我用过:
<img imageid="47" alt="cup." height="300" width="400" class="right" src="https://tneb.com/Services/Gets/Contents/ucr-images-v1/Images/cup-36" />
我使用的 XSL:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all">
<xsl:template match="img">
<xsl:element name="image">
<xsl:attribute name="id">
<xsl:value-of select="@imageid"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@alt"/>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="@height"/>
</xsl:attribute>
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
<xsl:attribute name="align">
<xsl:value-of select="@class"/>
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="@src"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我得到的输出为:
<image id="47"
alt="cup."
height="300"
width="400"
align="right"
href="https://tneb.com/Services/Gets/Contents/ucr-images-v1/Images/cup-36"/>
预期输出必须是:
<image id="47"
alt="cup."
height="300"
width="400"
align="right"
href="/ucr-images-v1/Images/cup-36"/>
我需要从图像的属性值中删除一些文本。最后 3 只表示文件夹结构。所以我只需要它本身。
请给我任何建议。提前致谢。
要仅获取路径的最后 3 个位置步骤,请更改:
<xsl:value-of select="@src"/>
至:
<xsl:value-of select="tokenize(@src, '/')[position() gt last() - 3]" separator="/"/>