【发布时间】:2011-04-06 01:38:20
【问题描述】:
我正在使用 xsl 将 xml 转换为 kml 格式。我想向 xsl 添加条件逻辑,以根据部分属性值切换 styleUrl。属性名称为FROM_SYSTEM_ID。属性值的格式是“A-123-CAM-1”,其中“CAM”是字符串的一部分,用于确定要使用的样式定义(在这种情况下,CAM 代表相机,CAB 代表橱柜等)。
如何解析这个属性来执行所需的样式定义切换?
以下是我的 xsl 模板:
<xsl:template match="Line">
<Folder>
<name>
Lines
<!--<xsl:value-of select="@name"/>-->
</name>
<xsl:for-each select="Row">
<Placemark>
<name>
<xsl:value-of select="@FROM_SYSTEM_ID"/>
</name>
<description>
<xsl:value-of select="@TO_SYSTEM_ID"/>
</description>
<styleUrl>#msn_open-diamond00</styleUrl>
<LineString>
<tessellate>1</tessellate>
<coordinates>
<xsl:value-of select="@FromLong"/>,<xsl:value-of select="@FromLat"/>,0 <xsl:value-of select="@ToLong"/>,<xsl:value-of select="@ToLat"/>,0
</coordinates>
</LineString>
</Placemark>
</xsl:for-each>
</Folder>
</xsl:template>
以下是 XML 的示例:
<Line>
<Row PrimaryRoute="A-123" FROM_SYSTEM_ID="A-123-CAB-1"
TO_SYSTEM_ID="A-123-CAM-3" FromLat="42.624948852000"
FromLong="-83.107221652500"
ToLat="42.624940325900" ToLong="-83.107353167000" />
<Row PrimaryRoute="A-123" FROM_SYSTEM_ID="A-123-CAM-1"
TO_SYSTEM_ID="A-123-HH-16" FromLat="42.641662528600"
FromLong="-83.151500129600"
ToLat="42.641709802200" ToLong="-83.151552587600" />
<!-- additional rows here -->
</Line>
【问题讨论】:
标签: xslt