必须从多个元素中选择标签时 XSLT 中的条件语句
我对 XSLT 比较陌生,但正在尝试学习它以便为客户提供解决方案。虽然最终目标是为 Filemaker Pro 编写 XSLT,但我想首先正确处理 HTML。
我收到一个生成的 XML 文件,其中包含旅游预订信息。它包含的信息以及订单数量也各不相同。
需要 XSLT 以更美观的表格形式呈现所有 XML 信息。
当我输入条件语句时,我的问题就开始了。在示例中,如果 BSServType 的值=“TUTU”,则表应反映一些信息,否则它应查找值“SOHO”,如果不是“SOVI”,则应查找值“SOHO”。
这个特定标签本身就是 DetSeg 的子标签。有多个 DetSeg 标签。不幸的是,该信息可能位于任何 1 标记中,因此 XSLT 应该能够查找正确的标记,然后选择其中一个值。我没能做到这一点。
第二个问题是下面的语句:当值为“TUTU”时,选择“BSServDest”似乎工作正常,因为它是“BSServType”的同级,但“BSServQuota”不是同级而是“侄子”,如果我可以这么说。这也带来了一个问题,因为我无法选择它们
,我希望我的解释足够清楚。 XML 和 XSLT 均已粘贴。我尝试在网站上查找问题是否已经出现,但没有找到任何可以完全帮助我的东西。我希望这个问题能够得到解决,因为还有几个条件语句我必须按照相同的逻辑编写。
我的另一个疑问是:以后为 Filemaker Pro 编写的 XSLT 是否容易改编?
提前感谢大家。
XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="order.xsl" type="text/xsl" ?>
<AllBookingFnp>
<BookingFnp>
<BookSegServ>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-07-02</BSDataFin>
<BSCodTGeogr>LOC</BSCodTGeogr>
<BSCodCGeogr>ATH</BSCodCGeogr>
<BSDesGeogr><![CDATA[ATENE]]></BSDesGeogr>
<BSServType>TUTU</BSServType>
<BSServCod>GREMETEORE</BSServCod>
<BSServDes><![CDATA[TOUR GRECIA CLASSICA E METEORE]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>GRECIT</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>1</BSservQtall>
<BSServQuota>DBLCDM</BSServQuota>
<BSServCodSist>DBL</BSServCodSist>
<BSServCodTrat>CDM</BSServCodTrat>
<BSServSist><![CDATA[DOPPIA]]></BSServSist>
<BSservTrat><![CDATA[COME DA PROGRAMMA]]></BSservTrat>
</BSSservSpec>
<BSFornText>SERVIZIO FORNITO DA:</BSFornText>
<BSFornDescr><![CDATA[PANHELLAS]]></BSFornDescr>
<BSFornInd><![CDATA[EL.VENIZELOU 161 N.ERYTHREA 14671]]></BSFornInd>
<BSFornLoc><![CDATA[ATHENS]]></BSFornLoc>
<BSFornTel>0030 210 8003073</BSFornTel>
<BSFornFax>Fax 8003030</BSFornFax>
</BookSeg>
<BookSeg>
<DetSeg>
<BSDataIni>2011-07-02</BSDataIni>
<BSDataFin>2011-07-09</BSDataFin>
<BSCodTGeogr>LOC</BSCodTGeogr>
<BSCodCGeogr>HYDV</BSCodCGeogr>
<BSDesGeogr><![CDATA[HYDRA - GRECIA]]></BSDesGeogr>
<BSServType>SOVI</BSServType>
<BSServCod>GREHYDRABEAC</BSServCod>
<BSServDes><![CDATA[HYDRA BEACH - VILLAGGIO VALTUR]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>GRECIA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>1</BSservQtall>
<BSServQuota>DBOCLAFV</BSServQuota>
<BSServCodSist>DBOCLA</BSServCodSist>
<BSServCodTrat>FV</BSServCodTrat>
<BSServSist><![CDATA[DOPPIA+letto uso doppia CLASSIC]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSAnagRis>
<BSAnagDesRis><![CDATA[]]></BSAnagDesRis>
<BSAnagIndRis><![CDATA[A.E. PLEPI-THERMISIA]]></BSAnagIndRis>
<BSAnagLocRis><![CDATA[ERMIONI]]></BSAnagLocRis>
<BSAnagTelRis></BSAnagTelRis>
<BSAnagFaxRis></BSAnagFaxRis>
</BSAnagRis>
<BSServNoteDet><![CDATA[NOTA BENE: ALL'ARRIVO GLI OSPITI CHE NON UTILIZZANO I TRASPORTI VALTUR]]></BSServNoteDet>
<BSServNoteDet><![CDATA[SONO ATTESI DOPO LE ORE 16:00. IL GIORNO DELLA VOSTRA PARTENZA VI]]></BSServNoteDet>
<BSServNoteDet><![CDATA[INVITIAMO A LIBERARE LE STANZE PRIMA DELLE ORE 10:00.]]></BSServNoteDet>
<BSServNoteDet><![CDATA[**********************************************************************]]></BSServNoteDet>
<BSFornInd><![CDATA[]]></BSFornInd>
<BSFornLoc><![CDATA[]]></BSFornLoc>
<BSFornTel></BSFornTel>
<BSFornFax></BSFornFax>
</BookSeg>
</BookSegServ>
</BookingFnp>
<BookingFnp>
<BookSegServ>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-06-25</BSDataFin>
<BSServType>TFTI</BSServType>
<BSServCod>NYCAPTHTL-I</BSServCod>
<BSServDes><![CDATA[TRANSFER APT NEW YORK-HOTEL]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>USA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>2</BSservQtall>
<BSServQuota></BSServQuota>
<BSServCodSist></BSServCodSist>
<BSServCodTrat></BSServCodTrat>
<BSServSist><![CDATA[]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSServFrom><![CDATA[AZ 642 FCO-EWR 25/06/11 13:45]]></BSServFrom>
<BSServTo><![CDATA[RADISSON LEXINGTON HOTEL]]></BSServTo>
<BSFornText>SERVIZIO FORNITO DA:</BSFornText>
<BSFornDescr><![CDATA[TEAM AMERICA INC]]></BSFornDescr>
<BSFornInd><![CDATA[125 PARK AVENUE, 2ND FLOOR]]></BSFornInd>
<BSFornLoc><![CDATA[NEW YORK]]></BSFornLoc>
<BSFornTel>001 212 6977165</BSFornTel>
<BSFornFax>Fax 7182471706</BSFornFax>
</BookSeg>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-07-02</BSDataFin>
<BSServType>SOHO</BSServType>
<BSServCod>NYCLEXINGTON</BSServCod>
<BSServDes><![CDATA[RADISSON LEXINGTON HOTEL]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>USA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>1</BSservQtall>
<BSServQuota>DBL</BSServQuota>
<BSServCodSist>DBL</BSServCodSist>
<BSServCodTrat></BSServCodTrat>
<BSServSist><![CDATA[DOPPIA]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSAnagRis>
<BSAnagDesRis><![CDATA[]]></BSAnagDesRis>
<BSAnagIndRis><![CDATA[]]></BSAnagIndRis>
<BSAnagLocRis><![CDATA[NEW YORK]]></BSAnagLocRis>
<BSAnagTelRis></BSAnagTelRis>
<BSAnagFaxRis></BSAnagFaxRis>
</BSAnagRis>
<BSFornInd><![CDATA[]]></BSFornInd>
<BSFornLoc><![CDATA[]]></BSFornLoc>
<BSFornTel></BSFornTel>
<BSFornFax></BSFornFax>
</BookSeg>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-06-25</BSDataFin>
<BSServType>TFTI</BSServType>
<BSServCod>NYCAPTHTL-O</BSServCod>
<BSServDes><![CDATA[TRANSFER HOTEL-APT NEW YORK]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>USA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>2</BSservQtall>
<BSServQuota></BSServQuota>
<BSServCodSist></BSServCodSist>
<BSServCodTrat></BSServCodTrat>
<BSServSist><![CDATA[]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSServFrom><![CDATA[AZ 642 FCO-EWR 25/06/11 13:45]]></BSServFrom>
<BSServTo><![CDATA[RADISSON LEXINGTON HOTEL]]></BSServTo>
<BSFornText>SERVIZIO FORNITO DA:</BSFornText>
<BSFornDescr><![CDATA[TEAM AMERICA INC]]></BSFornDescr>
<BSFornInd><![CDATA[125 PARK AVENUE, 2ND FLOOR]]></BSFornInd>
<BSFornLoc><![CDATA[NEW YORK]]></BSFornLoc>
<BSFornTel>001 212 6977165</BSFornTel>
<BSFornFax>Fax 7182471706</BSFornFax>
</BookSeg>
</BookSegServ>
</BookingFnp>
</AllBookingFnp>
XSLT:`
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Liste des commandes</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Destination</th>
<th>BSServQuota</th>
</tr>
<xsl:for-each select="AllBookingFnp/BookingFnp">
<tr>
<xsl:choose>
<xsl:when test="BookSegServ/BookSeg/DetSeg/BSServType='TUTU'">
<td><xsl:value-of select="BookSegServ/BookSeg/DetSeg/BSServDest" /></td>
<td><xsl:value-of select="BookSegServ/BookSeg/BSSservSpec/BSServQuota" /></td>
</xsl:when>
<xsl:when test="BookSegServ/BookSeg/DetSeg/BSServType='SOHO'">
<td><xsl:value-of select="BookSegServ/BookSeg/DetSeg/BSServDest" /></td>
<td><xsl:value-of select="BookSegServ/BookSeg/BSSservSpec/BSServQuota" /></td>
</xsl:when>
<xsl:when test="BookSegServ/BookSeg/DetSeg/BSServType='SOVI'">
<td><xsl:value-of select="BookSegServ/BookSeg/DetSeg/BSServDest" /></td>
<td><xsl:value-of select="BookSegServ/BookSeg/BSSservSpec/BSServQuota" /></td>
</xsl:when>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我得到的结果如下表所示:
目的地: GRECIT USA
BSServQuota: DBLCDM -
从 XML 文件中,信息为取自第一个
中的第一个
,因为它可以看到信息 TUTU 存在,但在第二行中,它无法这样做因为信息 TUTU/SOHO 或 SOVI 不存在于第一个
中,而是出现在第二个
中。它应该查看第二个
并验证“SOHO”,从而从
中选择“DBL”
我希望它查看所有内容三个
并查找值“TUTU”,如果存在,则显示我想要的信息,否则查找值“SOHO”,否则查找“SOVI”。
谢谢。
I am relatively new to XSLT but am trying to learn it to provide a solution for a client. Although the ultimate aim is to write an XSLT for Filemaker Pro, I would like to first get the HTML one right.
I receive a generated XML file which contains booking information for tours. The informatio it contains as well as the number of orders also varies.
The XSLT is needed to present all the XML info in a more presentable table form.
My problems begin when I put in the conditional statements. In the example if the value of BSServType='TUTU', the table should reflect some information, otherwise it should look for the value 'SOHO' and if not 'SOVI'.
This particular tag is itself a child of DetSeg. There are several DetSeg tags. Unfortunately, the info may be in any 1 tag so the XSLT should be capable of looking into the right one and then choosing one of the values. I have not been able to do so.
The second problem is the statement that follows: when the value is 'TUTU', select 'BSServDest' seems to be working fine as it is a sibling to 'BSServType' but 'BSServQuota' is not a sibling but rather a 'nephew' if I can say so. This also is posing a problem as I am unable to select them
I hope I have been clear enough in my explainations. The XML as well as the XSLT have been pasted. I have tried looking arounf the site to seeif the problem has already been presented but have nout found anything to help me completely. I hope this problem can be solved as there are several more conditional statements that I will have to write all following the same logic.
Another doubt I have: is it asy to adapt th XSLT that I amwriting for Filemaker Pro later?
Thanking everyone in advance.
The XML code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="order.xsl" type="text/xsl" ?>
<AllBookingFnp>
<BookingFnp>
<BookSegServ>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-07-02</BSDataFin>
<BSCodTGeogr>LOC</BSCodTGeogr>
<BSCodCGeogr>ATH</BSCodCGeogr>
<BSDesGeogr><![CDATA[ATENE]]></BSDesGeogr>
<BSServType>TUTU</BSServType>
<BSServCod>GREMETEORE</BSServCod>
<BSServDes><![CDATA[TOUR GRECIA CLASSICA E METEORE]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>GRECIT</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>1</BSservQtall>
<BSServQuota>DBLCDM</BSServQuota>
<BSServCodSist>DBL</BSServCodSist>
<BSServCodTrat>CDM</BSServCodTrat>
<BSServSist><![CDATA[DOPPIA]]></BSServSist>
<BSservTrat><![CDATA[COME DA PROGRAMMA]]></BSservTrat>
</BSSservSpec>
<BSFornText>SERVIZIO FORNITO DA:</BSFornText>
<BSFornDescr><![CDATA[PANHELLAS]]></BSFornDescr>
<BSFornInd><![CDATA[EL.VENIZELOU 161 N.ERYTHREA 14671]]></BSFornInd>
<BSFornLoc><![CDATA[ATHENS]]></BSFornLoc>
<BSFornTel>0030 210 8003073</BSFornTel>
<BSFornFax>Fax 8003030</BSFornFax>
</BookSeg>
<BookSeg>
<DetSeg>
<BSDataIni>2011-07-02</BSDataIni>
<BSDataFin>2011-07-09</BSDataFin>
<BSCodTGeogr>LOC</BSCodTGeogr>
<BSCodCGeogr>HYDV</BSCodCGeogr>
<BSDesGeogr><![CDATA[HYDRA - GRECIA]]></BSDesGeogr>
<BSServType>SOVI</BSServType>
<BSServCod>GREHYDRABEAC</BSServCod>
<BSServDes><![CDATA[HYDRA BEACH - VILLAGGIO VALTUR]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>GRECIA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>1</BSservQtall>
<BSServQuota>DBOCLAFV</BSServQuota>
<BSServCodSist>DBOCLA</BSServCodSist>
<BSServCodTrat>FV</BSServCodTrat>
<BSServSist><![CDATA[DOPPIA+letto uso doppia CLASSIC]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSAnagRis>
<BSAnagDesRis><![CDATA[]]></BSAnagDesRis>
<BSAnagIndRis><![CDATA[A.E. PLEPI-THERMISIA]]></BSAnagIndRis>
<BSAnagLocRis><![CDATA[ERMIONI]]></BSAnagLocRis>
<BSAnagTelRis></BSAnagTelRis>
<BSAnagFaxRis></BSAnagFaxRis>
</BSAnagRis>
<BSServNoteDet><![CDATA[NOTA BENE: ALL'ARRIVO GLI OSPITI CHE NON UTILIZZANO I TRASPORTI VALTUR]]></BSServNoteDet>
<BSServNoteDet><![CDATA[SONO ATTESI DOPO LE ORE 16:00. IL GIORNO DELLA VOSTRA PARTENZA VI]]></BSServNoteDet>
<BSServNoteDet><![CDATA[INVITIAMO A LIBERARE LE STANZE PRIMA DELLE ORE 10:00.]]></BSServNoteDet>
<BSServNoteDet><![CDATA[**********************************************************************]]></BSServNoteDet>
<BSFornInd><![CDATA[]]></BSFornInd>
<BSFornLoc><![CDATA[]]></BSFornLoc>
<BSFornTel></BSFornTel>
<BSFornFax></BSFornFax>
</BookSeg>
</BookSegServ>
</BookingFnp>
<BookingFnp>
<BookSegServ>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-06-25</BSDataFin>
<BSServType>TFTI</BSServType>
<BSServCod>NYCAPTHTL-I</BSServCod>
<BSServDes><![CDATA[TRANSFER APT NEW YORK-HOTEL]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>USA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>2</BSservQtall>
<BSServQuota></BSServQuota>
<BSServCodSist></BSServCodSist>
<BSServCodTrat></BSServCodTrat>
<BSServSist><![CDATA[]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSServFrom><![CDATA[AZ 642 FCO-EWR 25/06/11 13:45]]></BSServFrom>
<BSServTo><![CDATA[RADISSON LEXINGTON HOTEL]]></BSServTo>
<BSFornText>SERVIZIO FORNITO DA:</BSFornText>
<BSFornDescr><![CDATA[TEAM AMERICA INC]]></BSFornDescr>
<BSFornInd><![CDATA[125 PARK AVENUE, 2ND FLOOR]]></BSFornInd>
<BSFornLoc><![CDATA[NEW YORK]]></BSFornLoc>
<BSFornTel>001 212 6977165</BSFornTel>
<BSFornFax>Fax 7182471706</BSFornFax>
</BookSeg>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-07-02</BSDataFin>
<BSServType>SOHO</BSServType>
<BSServCod>NYCLEXINGTON</BSServCod>
<BSServDes><![CDATA[RADISSON LEXINGTON HOTEL]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>USA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>1</BSservQtall>
<BSServQuota>DBL</BSServQuota>
<BSServCodSist>DBL</BSServCodSist>
<BSServCodTrat></BSServCodTrat>
<BSServSist><![CDATA[DOPPIA]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSAnagRis>
<BSAnagDesRis><![CDATA[]]></BSAnagDesRis>
<BSAnagIndRis><![CDATA[]]></BSAnagIndRis>
<BSAnagLocRis><![CDATA[NEW YORK]]></BSAnagLocRis>
<BSAnagTelRis></BSAnagTelRis>
<BSAnagFaxRis></BSAnagFaxRis>
</BSAnagRis>
<BSFornInd><![CDATA[]]></BSFornInd>
<BSFornLoc><![CDATA[]]></BSFornLoc>
<BSFornTel></BSFornTel>
<BSFornFax></BSFornFax>
</BookSeg>
<BookSeg>
<DetSeg>
<BSDataIni>2011-06-25</BSDataIni>
<BSDataFin>2011-06-25</BSDataFin>
<BSServType>TFTI</BSServType>
<BSServCod>NYCAPTHTL-O</BSServCod>
<BSServDes><![CDATA[TRANSFER HOTEL-APT NEW YORK]]></BSServDes>
<BSServTimeIni></BSServTimeIni>
<BSServDest>USA</BSServDest>
</DetSeg>
<BSSservSpec>
<BSservQtall>2</BSservQtall>
<BSServQuota></BSServQuota>
<BSServCodSist></BSServCodSist>
<BSServCodTrat></BSServCodTrat>
<BSServSist><![CDATA[]]></BSServSist>
<BSservTrat><![CDATA[]]></BSservTrat>
</BSSservSpec>
<BSServFrom><![CDATA[AZ 642 FCO-EWR 25/06/11 13:45]]></BSServFrom>
<BSServTo><![CDATA[RADISSON LEXINGTON HOTEL]]></BSServTo>
<BSFornText>SERVIZIO FORNITO DA:</BSFornText>
<BSFornDescr><![CDATA[TEAM AMERICA INC]]></BSFornDescr>
<BSFornInd><![CDATA[125 PARK AVENUE, 2ND FLOOR]]></BSFornInd>
<BSFornLoc><![CDATA[NEW YORK]]></BSFornLoc>
<BSFornTel>001 212 6977165</BSFornTel>
<BSFornFax>Fax 7182471706</BSFornFax>
</BookSeg>
</BookSegServ>
</BookingFnp>
</AllBookingFnp>
The XSLT:`
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Liste des commandes</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Destination</th>
<th>BSServQuota</th>
</tr>
<xsl:for-each select="AllBookingFnp/BookingFnp">
<tr>
<xsl:choose>
<xsl:when test="BookSegServ/BookSeg/DetSeg/BSServType='TUTU'">
<td><xsl:value-of select="BookSegServ/BookSeg/DetSeg/BSServDest" /></td>
<td><xsl:value-of select="BookSegServ/BookSeg/BSSservSpec/BSServQuota" /></td>
</xsl:when>
<xsl:when test="BookSegServ/BookSeg/DetSeg/BSServType='SOHO'">
<td><xsl:value-of select="BookSegServ/BookSeg/DetSeg/BSServDest" /></td>
<td><xsl:value-of select="BookSegServ/BookSeg/BSSservSpec/BSServQuota" /></td>
</xsl:when>
<xsl:when test="BookSegServ/BookSeg/DetSeg/BSServType='SOVI'">
<td><xsl:value-of select="BookSegServ/BookSeg/DetSeg/BSServDest" /></td>
<td><xsl:value-of select="BookSegServ/BookSeg/BSSservSpec/BSServQuota" /></td>
</xsl:when>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The result I am getting is the following in a table:
Destination: GRECIT USA
BSServQuota: DBLCDM -
From the XML file, the info is being taken from the first <DetSeg>
from the first <BookingFnp>
as it can see the info TUTU present but in the second row, it is unable to do so as the info TUTU/SOHO or SOVI is not present in the first <DetSeg>
but in the second one. It is supposed to look in the second <DetSeg>
and validate 'SOHO' and thus choose 'DBL' from <BSServQuota>
I would like it to look at all three <DetSeg>
and look for the value 'TUTU', and if present, prsent the info I want, otherwise look for the value 'SOHO' and otherwise 'SOVI'.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你在这里陷入了一个陷阱:你看到了像 for-each 这样的结构,并选择了其他语言中看起来熟悉的结构,并且你本能地优先使用它们,而不是其他不太熟悉的结构。因此,您并不是以“XSLT 方式”编写代码。 XSLT 方法是使用模板规则:匹配输入中出现的特定模式的模板。这有时称为“推式处理”,以区别于“拉式处理”。
所以这种代码:
应该这样写:
使用与 BSServType 的其他值相匹配的进一步模板规则。
(我只是想在这里为您指出正确的方向,而不是提供工作代码)。
You're falling into a trap here: you're seeing constructs like for-each and choose that look familiar from other languages, and you're instinctively using them in preference to other less familiar constructs. As a result, you're not writing your code "the XSLT way". The XSLT way is to use template rules: templates that match particular patterns occurring in the input. This is sometimes called "push processing" as distinct from "pull processing".
So this kind of code:
should be written like this:
with further template rules that match other values of BSServType.
(I'm only trying to point you in the right direction here, not to provide working code).
我设法得到答案并让我的 XSLT 正常工作。我得到了专家的帮助,但我想我会分享答案:
迈克尔·凯(Michael Kay)让我走上了正确的道路,但我自己无法做到这一点,但无论如何,这里是:
感谢所有试图帮助我的人。
I managed to get the answer and get my XSLT working. I had the help of an expert but I thought I would share the answer:
Michael Kay had put me on the right track but I had been unable to do it on my own but anyway here it is:
Thanks to everyone who tried to help me.
这里有一个完全模板驱动的示例解决方案(没有循环,没有选择):
Here you have an example solution totally template driven (no loops, no choose):