gpt4 book ai didi

xslt - 检查起始字符应该是 'T' 并且接下来的 3 个字符应该是 xslt 中的数字

转载 作者:行者123 更新时间:2023-12-04 20:58:05 26 4
gpt4 key购买 nike

我使用 XSLT1.0 来转换我的 XML。

我有以下 Tabs.xml

<?xml version="1.0"?>
<tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:481-87289-4" Managed="68">
<tcm:Item ID="tcm:481-596728-64" Title="T000. Brisbane" pageURL="/australia/brisbane/index.aspx" componentTitle="Overview"/>
<tcm:Item ID="tcm:481-598671-64" Title="Tabs XML"/>
<tcm:Item ID="tcm:481-598672-64" Title="T030 Special Offers" pageURL="/australia/brisbane/specialoffers.aspx" componentTitle="Special Offers"/>
<tcm:Item ID="tcm:481-598673-64" Title="020 Flight Schedules" pageURL="/australia/brisbane/flightschedules.aspx" componentTitle="Flight Schedules"/>
<tcm:Item ID="tcm:481-598674-64" Title="T010 Guide" pageURL="/australia/brisbane/guide.aspx" componentTitle="Guide"/>
</tcm:ListItems>

我正在使用下面的 xslt 来转换它!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tcm="http://www.tridion.com/ContentManager/5.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:em="http://www.emirates.com/tridion/schemas" xmlns:tcmse="http://www.tridion.com/ContentManager/5.1/TcmScriptAssistant" exclude-result-prefixes="em xlink tcmse tcm">
<xsl:output method="xml" version="1.0" encoding="UTF-16" indent="yes"/>
<xsl:template match="tcm:ListItems">
<list type="Tabs">
<xsl:apply-templates select="tcm:Item">
<xsl:sort select="@Title" order="ascending"/>
</xsl:apply-templates>
</list>
</xsl:template>
<!-- add field values for each item-->
<xsl:template match="tcm:Item">
<xsl:if test="@componentTitle != ''">
<xsl:element name="tab">
<xsl:attribute name="id">
<xsl:value-of select="substring-after(@ID, '-')"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="@componentTitle"/>
</xsl:attribute>
<xsl:attribute name="url">
<xsl:value-of select="@pageURL"/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

以前,它工作正常,但现在需要进行另一项更改,现在我需要渲染那些@Title 以 'T' 或 't' 开头的节点,并且接下来的 3 个字符应该是数字,例如在上面的 xml 中“航类时刻表”不应该来,我想我只需要在 <xsl:if test="@componentTitle != ''"> 中再写一个和条件,

请建议!怎么办!

最佳答案

这是进行匹配的最简单的表达式:

translate(substring(@Title, 1, 4), 't12345679', 'T000000000') = 'T000'

这是模板:
<xsl:template match="
tcm:Item[translate(substring(@Title, 1, 4), 't12345679', 'T000000000') = 'T000'
and @componentTitle != '' "/>

关于xslt - 检查起始字符应该是 'T' 并且接下来的 3 个字符应该是 xslt 中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3645234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com