【问题标题】:Create a Table using LandXML使用 LandXML 创建表
【发布时间】:2018-11-12 02:01:33
【问题描述】:

我正在使用 LandXML 创建下表,但我想填充纬度和经度而不是北距和东距值。

Original Result

Desired Result

我知道 AlignPI 具有如下所示的属性和嵌套属性,但我很难集中精力访问它们并将它们放入实际表中。 [AlignPIs属性映射][3]

AlignPI Mapping

PI Mapping

这就是我目前的代码

 <?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:lx="http://www.landxml.org/schema/LandXML-1.2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:landUtils="http://www.autodesk.com/land/civil/vcedit"
	xmlns:lxml="urn:lx_utils">
	<!--Description:Tabulation of Alignment PI with Station, Latitude and Longitude.
This form is valid for LandXML 0.88, 1.0, 1.1 and 1.2 data.-->
	<!--CreatedBy:Mark Hultgren -->
	<!--DateCreated:06/01/2018 -->
	<!--LastModifiedBy:Mark Hultgren -->
	<!--DateModified:06/01/2018 -->
	<!--OutputExtension:html -->
	<xsl:output method="html" encoding="UTF-8" />
	<!-- ==== JavaScript Includes ==== -->
	<xsl:include href="header.xsl" />
	<xsl:include href="UELS_Alignment_Layout.xsl" />
	<!--AlignmentPI Parameters-->
	<xsl:param name="PINumber" select="//lx:AlignPI/*/@pntRef" />
	<xsl:param name="PIStation" select="//lx:AlignPI/*/@Station" />
	<xsl:param name="PILatitude" select="//lx:AlignPI/*/@latitude" />
	<xsl:param name="PILongitude" select="//lx:AlignPI/*/@longitude" />
		<xsl:template match="/">
			<xsl:for-each select="AlignPIs" test="//lx:AlignPI/*/@PI">
				<!--if there is diameterUnit, use it as pipe diameter dimension unit-->
				<xsl:value-of select="//lx:Units/*/@diameterUnit" />
			</xsl:for-each>
			<xsl:otherwise>
				<!--otherwise, use linearUnit-->
				<xsl:value-of select="//lx:Units/*/@linearUnit" />
			</xsl:otherwise>
		</xsl:template>
	</xsl:param>
		<!-- ============================= -->
	<xsl:template match="/">
		<html>
			<head>
				<title>Alignment PI Station report with Latitude and Longitude<br/>  for <xsl:value-of select="//lx:Project/@name" /></title>
				<style type="text/css">
					div{
					width:10.5in;
					font-family:Verdana;
					}
					th{
					font-size:12pt;
					text-align:center;
					text-decoration:underline;
					}
					td{
					padding:0.02in 0.15in;
					text-align:right;
					}
					tr{
					font-size:10pt;
					}
				</style>
			</head>
			<body>
				<div>
					<xsl:call-template name="AutoHeader">
						<xsl:with-param name="ReportTitle">Alignment PI Report</xsl:with-param>
						<xsl:with-param name="ReportDesc">
							<xsl:value-of select="//lx:Project/@name" />
						</xsl:with-param>
					</xsl:call-template>
					<br />
					<xsl:for-each select="//lx:Alignment/lx:AlignPIs">					
					<b>Alignment: <xsl:value-of select="@name" /></b>
					<br />Project Name [(Edit This)]
					<table bordercolor="black" border="1" cellspacing="0" width="100%">
							<tr>
								<th>ID</th>
								<th>Station</th>
								<th>Latitude</th>
								<th>Longitude</th>
							</tr>
							<xsl:for-each select="./lx:AlignPIs/lx:AlignPI">
								<tr>
									<xsl:variable name="PINumber" select="pntRef/@text()"
									<xsl:variable name="Station" select="AlignPI/@Station" />
									<xsl:variable name="PI" select="latitude" />
									<xsl:variable name="PI" select="longitude" />
									<td>
										<xsl:value-of select="$PINumber" />
									</td>
									<td>
										<xsl:value-of select="$Station" />
									</td>
									<td>
										<xsl:value-of select="$latitude" />
									</td>
									<td>
										<xsl:value-of select="$longitude" />
									</td>
							</xsl:for-each>
					</table>
				</div>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

【问题讨论】:

    标签: xml xslt xpath transformation


    【解决方案1】:

    您的 XPath 表达式和上下文节点似乎存在一些问题。 您从 AlignPIs 的上下文节点开始:

    <xsl:for-each select="//lx:Alignment/lx:AlignPIs">
    

    在这种情况下,“。”指的是 XSLT 处理器当前正在处理的 lx:AlignPIs 元素。在接下来的内部 for-each 中,您必须编写以下代码来选择当前上下文中的所有 &lt;AlignPi&gt; 元素:

    <xsl:for-each select="lx:AlignPI">
    

    &lt;xsl:for-each select="./lx:AlignPI"&gt; 是等效语句)

    现在您在第二个 for-each 块内的上下文节点是 lx:AlignPI。

    定义变量时,您尝试引用 PI 子元素的纬度和经度属性。 试试下面的经纬度表达式:

    <xsl:variable name="latitude" select="lx:PI/@latitude" />
    <xsl:variable name="longitude" select="lx:PI/@longitude" />
    

    详细说明一下:正如我所提到的,在内部 &lt;xsl:for-each ...&gt; 中,您的上下文节点现在是 lx:AlignPI。纬度和经度属性不附加到 lx:AlignPI,而是附加到 PI 子元素。因此,在您的 XPath 语句中,您需要先“导航”到 lx:PI 元素,然后从那里访问属性。

    【讨论】:

    • 谢谢@Kai,这是我现在在参数部分的内容 [code]
    猜你喜欢
    • 1970-01-01
    • 2012-07-07
    • 2021-11-20
    • 2019-05-21
    • 2017-04-12
    • 2013-01-16
    • 2019-07-09
    • 2013-11-03
    • 2014-05-16
    相关资源
    最近更新 更多