我正在尝试更改/修复现有的 xslt1.0 样式表,但我不明白为什么它不起作用。
这是 XML 的一部分:
l: part of the xml
<Survey>
<SurveyHeader name="230222-CODE-TEST_1"/>
<Equipment>
<GPSReceiverDetails id="GPS_1" manufacturer="Leica Geosystems AG" model=" " serialNumber=" "/>
</Equipment>
<GPSSetup id="GPSSetupID_4" GPSReceiverDetailsID="GPS_1" antennaHeight="1.544000" stationName="GPS0001">
<GPSPosition pntRef="GPS0001" wgsLatitude="53.201424895062324" wgsLongitude="6.564586909979438" wgsHeight="42.733122">
<TargetPoint name="GPS0001" pntRef="GPS0001" >580062.951336 233674.586902 1.958197</TargetPoint>
<GPSQCInfoLevel2 covarianceXX="0.0000556906" covarianceXY="-0.0000044136" covarianceXZ="0.0000055377" covarianceYY="0.0000384521" covarianceYZ="0.0000021151" covarianceZZ="0.0000702572" RMS="1.000000" startTime="1361092385" stopTime="1361092385"/>
</GPSPosition>
</GPSSetup>
</Survey>
h: part of the xml
<Survey name="230222-CODE-TEST_1" SurveyDuration="P0Y0M0DT0H4M4S">
<GPSSetup uniqueID="GPSSetupID_4">
<GPSPosition targetPntRef="GPS0001" tiltCompensated="true" verticalOffset="0.000000">
<GPSQuality HDOP="0.600000" GDOP="1.878829" PDOP="1.252996" VDOP="1.100000" TDOP="1.400000"/>
<SatelliteInfo GPSSatTracked="9" GPSSatUsed="9" GALILEOSatTracked="4" GALILEOSatUsed="4" GLONASSSatTracked="6" GLONASSSatUsed="5" BEIDOUSatTracked="12" BEIDOUSatUsed="12"/>
<RTKInfo referenceRef="RTCM-Ref 0028" networkSolution="true" networkType="i-MAX" dataFormat="RTCM v3" ipAddress="nl.nrtk.eu" port="7801" mountpoint="MSM_iMAX" insideRTKNetwork="Inside" GPUID="" numRefStationUsed="1" numRTKPositionUsed="0"/>
<GPSPositionVelocity velocityX="0.017137" velocityY="0.001990" velocityZ="-0.010346" linearVelocityUnit="linearUnitPerSecond">
<VelocityQuality Qxx="0.00073671" Qxy="-0.00014277" Qxz="0.00014533" Qyy="0.00039546" Qyz="-0.00000568" Qzz="0.00262066" MeanError="1.00000000"/>
</GPSPositionVelocity>
<TiltInfo tilt="2.09289226" tiltQuality="0.20604831" maxTilt="2.09289172" maxTiltQuality="0.20604831" tiltDirection="292.82119353" tiltDirectionQuality="6.73585423" antennaHeading="126.49655262" antennaHeadingQuality="1.56022984">
<AttitudeQuaternion w="0.545783971615954" x="0.014694157165700" y="-0.007365463010343" z="-0.837764697290921">
<QuaternionQuality Qxx="0.0000105379" Qxy="0.0000002941" Qxz="-0.0000101108" Qyy="0.0000108098" Qyz="0.0000066687" Qzz="0.0008271720" MeanError="63.6619772368"/>
</AttitudeQuaternion>
<AngularVelocity velocityX="-3.1438191155" velocityY="1.5740678692" velocityZ="-1.4080006143" AngularVelocityType="angularUnitPerSecond">
<VelocityQuality Qxx="0.0000001490" Qxy="0.0000002552" Qxz="-0.0000000169" Qyy="0.0000005309" Qyz="0.0000000154" Qzz="0.0000003482" MeanError="63.6619772368"/>
</AngularVelocity>
<LeverArm deltaNorth="0.001000" deltaEast="0.000280" deltaUp="-1.643910"/>
</TiltInfo>
</GPSPosition>
</GPSSetup>
</Survey>
在 xslt 模板中,我有以下键和变量:
<xsl:key name="KeyGPSPositionH" match="h:GPSPosition" use="@targetPntRef" />
<xsl:template match="l:GPSPosition">
<xsl:variable name="gpsSetupH" select="key('KeyGPSPositionH',@pntRef)" />
如果我然后使用:
<xsl:value-of select="$gpsSetupH/h:GPSQuality/@HDOP" />
它从 xml 返回 HDOP 的值
或者:
<xsl:value-of select="$gpsSetupH/h:SatelliteInfo/@GPSSatTracked" />
它从 xml 返回 GPSSatTracked 的值
但是如果我把它改成:
<xsl:value-of select="$gpsSetupH/h:TiltInfo/@tiltQuality" />
或 <xsl:value-of select="$gpsSetupH/@verticalOffset" />
尽管它与其他两个具有相同的父标签,但它什么也不返回。
我试图将其更改为
<xsl:value-of select="$gpsSetupH/h:GPSPosition/h:TiltInfo/@tiltQuality" />
并更改密钥以使其在调查标签中开始 <xsl:key name="KeySurveyH" match="h:Survey" use="h:GPSSetup/h:GPSPosition/@targetPntRef" />
但是这两个选项都不起作用。
当我将 XSLT 1.0 与 XslCompiledTransform 一起使用并尝试将您的代码片段变成最小的、格式化的、完整的示例时,我得到的 XML 为
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Survey>
<SurveyHeader name="230222-CODE-TEST_1"/>
<Equipment>
<GPSReceiverDetails id="GPS_1"
manufacturer="Leica Geosystems AG"
model=" "
serialNumber=" "/>
</Equipment>
<GPSSetup id="GPSSetupID_4"
GPSReceiverDetailsID="GPS_1"
antennaHeight="1.544000"
stationName="GPS0001">
<GPSPosition pntRef="GPS0001"
wgsLatitude="53.201424895062324"
wgsLongitude="6.564586909979438"
wgsHeight="42.733122">
<TargetPoint name="GPS0001" pntRef="GPS0001">580062.951336 233674.586902 1.958197</TargetPoint>
<GPSQCInfoLevel2 covarianceXX="0.0000556906"
covarianceXY="-0.0000044136"
covarianceXZ="0.0000055377"
covarianceYY="0.0000384521"
covarianceYZ="0.0000021151"
covarianceZZ="0.0000702572"
RMS="1.000000"
startTime="1361092385"
stopTime="1361092385"/>
</GPSPosition>
</GPSSetup>
</Survey>
<Survey name="230222-CODE-TEST_1" SurveyDuration="P0Y0M0DT0H4M4S">
<GPSSetup uniqueID="GPSSetupID_4">
<GPSPosition targetPntRef="GPS0001"
tiltCompensated="true"
verticalOffset="0.000000">
<GPSQuality HDOP="0.600000"
GDOP="1.878829"
PDOP="1.252996"
VDOP="1.100000"
TDOP="1.400000"/>
<SatelliteInfo GPSSatTracked="9"
GPSSatUsed="9"
GALILEOSatTracked="4"
GALILEOSatUsed="4"
GLONASSSatTracked="6"
GLONASSSatUsed="5"
BEIDOUSatTracked="12"
BEIDOUSatUsed="12"/>
<RTKInfo referenceRef="RTCM-Ref 0028"
networkSolution="true"
networkType="i-MAX"
dataFormat="RTCM v3"
ipAddress="nl.nrtk.eu"
port="7801"
mountpoint="MSM_iMAX"
insideRTKNetwork="Inside"
GPUID=""
numRefStationUsed="1"
numRTKPositionUsed="0"/>
<GPSPositionVelocity velocityX="0.017137"
velocityY="0.001990"
velocityZ="-0.010346"
linearVelocityUnit="linearUnitPerSecond">
<VelocityQuality Qxx="0.00073671"
Qxy="-0.00014277"
Qxz="0.00014533"
Qyy="0.00039546"
Qyz="-0.00000568"
Qzz="0.00262066"
MeanError="1.00000000"/>
</GPSPositionVelocity>
<TiltInfo tilt="2.09289226"
tiltQuality="0.20604831"
maxTilt="2.09289172"
maxTiltQuality="0.20604831"
tiltDirection="292.82119353"
tiltDirectionQuality="6.73585423"
antennaHeading="126.49655262"
antennaHeadingQuality="1.56022984">
<AttitudeQuaternion w="0.545783971615954"
x="0.014694157165700"
y="-0.007365463010343"
z="-0.837764697290921">
<QuaternionQuality Qxx="0.0000105379"
Qxy="0.0000002941"
Qxz="-0.0000101108"
Qyy="0.0000108098"
Qyz="0.0000066687"
Qzz="0.0008271720"
MeanError="63.6619772368"/>
</AttitudeQuaternion>
<AngularVelocity velocityX="-3.1438191155"
velocityY="1.5740678692"
velocityZ="-1.4080006143"
AngularVelocityType="angularUnitPerSecond">
<VelocityQuality Qxx="0.0000001490"
Qxy="0.0000002552"
Qxz="-0.0000000169"
Qyy="0.0000005309"
Qyz="0.0000000154"
Qzz="0.0000003482"
MeanError="63.6619772368"/>
</AngularVelocity>
<LeverArm deltaNorth="0.001000" deltaEast="0.000280" deltaUp="-1.643910"/>
</TiltInfo>
</GPSPosition>
</GPSSetup>
</Survey>
</root>
XSLT 为
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="KeyGPSPositionH" match="GPSPosition" use="@targetPntRef" />
<xsl:template match="@* | node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="GPSPosition[@pntRef]">
<xsl:call-template name="identity"/>
<xsl:variable name="gpsSetupH" select="key('KeyGPSPositionH',@pntRef)" />
<xsl:comment>
<xsl:text>tiltQuality: </xsl:text>
<xsl:value-of select="$gpsSetupH/TiltInfo/@tiltQuality" />
<xsl:text>; verticalOffset: </xsl:text>
<xsl:value-of select="$gpsSetupH/@verticalOffset"/>
</xsl:comment>
</xsl:template>
<xsl:output indent="yes"/>
</xsl:stylesheet>
结果为
<?xml version="1.0" encoding="utf-16"?>
<root>
<Survey>
<SurveyHeader name="230222-CODE-TEST_1" />
<Equipment>
<GPSReceiverDetails id="GPS_1" manufacturer="Leica Geosystems AG" model=" " serialNumber=" " />
</Equipment>
<GPSSetup id="GPSSetupID_4" GPSReceiverDetailsID="GPS_1" antennaHeight="1.544000" stationName="GPS0001">
<GPSPosition pntRef="GPS0001" wgsLatitude="53.201424895062324" wgsLongitude="6.564586909979438" wgsHeight="42.733122">
<TargetPoint name="GPS0001" pntRef="GPS0001">580062.951336 233674.586902 1.958197</TargetPoint>
<GPSQCInfoLevel2 covarianceXX="0.0000556906" covarianceXY="-0.0000044136" covarianceXZ="0.0000055377" covarianceYY="0.0000384521" covarianceYZ="0.0000021151" covarianceZZ="0.0000702572" RMS="1.000000" startTime="1361092385" stopTime="1361092385" />
</GPSPosition><!--tiltQuality: 0.20604831; verticalOffset: 0.000000-->
</GPSSetup>
</Survey>
<Survey name="230222-CODE-TEST_1" SurveyDuration="P0Y0M0DT0H4M4S">
<GPSSetup uniqueID="GPSSetupID_4">
<GPSPosition targetPntRef="GPS0001" tiltCompensated="true" verticalOffset="0.000000">
<GPSQuality HDOP="0.600000" GDOP="1.878829" PDOP="1.252996" VDOP="1.100000" TDOP="1.400000" />
<SatelliteInfo GPSSatTracked="9" GPSSatUsed="9" GALILEOSatTracked="4" GALILEOSatUsed="4" GLONASSSatTracked="6" GLONASSSatUsed="5" BEIDOUSatTracked="12" BEIDOUSatUsed="12" />
<RTKInfo referenceRef="RTCM-Ref 0028" networkSolution="true" networkType="i-MAX" dataFormat="RTCM v3" ipAddress="nl.nrtk.eu" port="7801" mountpoint="MSM_iMAX" insideRTKNetwork="Inside" GPUID="" numRefStationUsed="1" numRTKPositionUsed="0" />
<GPSPositionVelocity velocityX="0.017137" velocityY="0.001990" velocityZ="-0.010346" linearVelocityUnit="linearUnitPerSecond">
<VelocityQuality Qxx="0.00073671" Qxy="-0.00014277" Qxz="0.00014533" Qyy="0.00039546" Qyz="-0.00000568" Qzz="0.00262066" MeanError="1.00000000" />
</GPSPositionVelocity>
<TiltInfo tilt="2.09289226" tiltQuality="0.20604831" maxTilt="2.09289172" maxTiltQuality="0.20604831" tiltDirection="292.82119353" tiltDirectionQuality="6.73585423" antennaHeading="126.49655262" antennaHeadingQuality="1.56022984">
<AttitudeQuaternion w="0.545783971615954" x="0.014694157165700" y="-0.007365463010343" z="-0.837764697290921">
<QuaternionQuality Qxx="0.0000105379" Qxy="0.0000002941" Qxz="-0.0000101108" Qyy="0.0000108098" Qyz="0.0000066687" Qzz="0.0008271720" MeanError="63.6619772368" />
</AttitudeQuaternion>
<AngularVelocity velocityX="-3.1438191155" velocityY="1.5740678692" velocityZ="-1.4080006143" AngularVelocityType="angularUnitPerSecond">
<VelocityQuality Qxx="0.0000001490" Qxy="0.0000002552" Qxz="-0.0000000169" Qyy="0.0000005309" Qyz="0.0000000154" Qzz="0.0000003482" MeanError="63.6619772368" />
</AngularVelocity>
<LeverArm deltaNorth="0.001000" deltaEast="0.000280" deltaUp="-1.643910" />
</TiltInfo>
</GPSPosition>
</GPSSetup>
</Survey>
</root>
输出注释
<!--tiltQuality: 0.20604831; verticalOffset: 0.000000-->
建议XPath表达式查找数据。
因此,请考虑提供最少但完整的示例,以便我们重现问题,以及有关您使用的 XSLT 1.0 处理器的信息。