XSLT How to call XML item without ID partameter?

纵饮孤独 提交于 2021-02-11 15:16:34

问题


I have to create HTML table using XML data file and XSLT style sheet with <xsl:for-each> instruction. I should use names of items included into XML file.

My data are organised in one XML file in two ways. Structure is as below:

<Data>
   <FieldBook> (...) </FieldBook>
   <Reductions>  (...) </Reductions>
</Data>

<FieldBook>
<PointRecord ID="00000017" TimeStamp="2020-08-04T14:42:41">
            <Name>osn2t</Name>
            <Code></Code>
            <Description1 Name="Description">k</Description1>
            <Method>GpsStaticObservation</Method>
            <SurveyMethod>NetworkFix</SurveyMethod>
            <Classification>Stakeout</Classification>
            <Deleted>false</Deleted>
            <ECEFDeltas>
                <DeltaX>-23.63342856942</DeltaX>
                <DeltaY>-3.16591248824</DeltaY>
                <DeltaZ>10.47772248089</DeltaZ>
            </ECEFDeltas>
            <Precision>
                <Horizontal>0.01284883061</Horizontal>
                <Vertical>0.01942246037</Vertical>
            </Precision>
            <QualityControl1>
                <NumberOfSatellites>12</NumberOfSatellites>
                <RelativeDOPs>false</RelativeDOPs>
                <PDOP>1.20000000000</PDOP>
                <HDOP>0.70000000000</HDOP>
                <VDOP>1.00000000000</VDOP>
                <RMS>57.01754385965</RMS>
                <NumberOfPositionsUsed>7</NumberOfPositionsUsed>
                <HorizontalStandardDeviation></HorizontalStandardDeviation>
                <VerticalStandardDeviation></VerticalStandardDeviation>
                <StartTime>
                    <GPSWeek>2117</GPSWeek>
                    <Seconds>218550.0000</Seconds>
                </StartTime>
                <EndTime>
                    <GPSWeek>2117</GPSWeek>
                    <Seconds>218575.0000</Seconds>
                </EndTime>
                <MonitorStatus>NotMonitored</MonitorStatus>
            </QualityControl1>
            <QualityControl2>
                <NumberOfSatellites>12</NumberOfSatellites>
                <ErrorScale>0.010833333</ErrorScale>
                <VCVxx>0.00003600000</VCVxx>
                <VCVxy>0.00000339435</VCVxy>
                <VCVxz>0.00002158332</VCVxz>
                <VCVyy>0.00000900000</VCVyy>
                <VCVyz>0.00000853788</VCVyz>
                <VCVzz>0.00010000000</VCVzz>
                <UnitVariance>0.0</UnitVariance>
            </QualityControl2>
            <AntennaID>00000015</AntennaID>
            <RTK_Base>VRS1</RTK_Base>
            <ComputedGrid>
                <North>5544447.5666</North>
                <East>7424116.2708</East>
                <Elevation>213.2381</Elevation>
            </ComputedGrid>
            <Stakeout>
                <PointDesign>
                    <Name>osn2</Name>
                    <Code></Code>
                    <StakeoutMethod>ToThePoint</StakeoutMethod>
                    <DesignElevation>213.2180</DesignElevation>
                </PointDesign>
                <GridDeltas>
                    <DeltaNorth>0.0104</DeltaNorth>
                    <DeltaEast>0.0132</DeltaEast>
                    <DeltaElevation>-0.0201</DeltaElevation>
                </GridDeltas>
            </Stakeout>
        </PointRecord>
...
</FieldBook>

and

<Reductions>
        <Point>
            <ID>00000017</ID>
            <Name>osn2t</Name>
            <Code></Code>
            <Description1 Name="Description">k</Description1>
            <SurveyMethod>NetworkFix</SurveyMethod>
            <Classification>Stakeout</Classification>
            <Grid>
                <North>5544447.5666</North>
                <East>7424116.2708</East>
                <Elevation>213.2381</Elevation>
            </Grid>
            <WGS84>
                <Latitude>50.03137528405</Latitude>
                <Longitude>19.94080538786</Longitude>
                <Height>253.0977</Height>
            </WGS84>
        </Point>
</Reductions>

I get necessary data from one part of XML tree (FieldBook) using such code for NumberOfSatellites, but I don't know how to get it eg. for second field, from Reductions items:

<xsl:template match="PointRecord">
  <xsl:for-each select="/Data/FieldBook/PointRecord[Deleted!='true']"></xsl:for-each>
    <xsl:if test="ECEFDeltas/DeltaX/text()">
      <tr>
        (...)
        <td>
          <xsl:call-template name="my-out">
            <xsl:with-param name="Val" select="QualityControl1/NumberOfSatellites"/>
          </xsl:call-template>
        </td>
          (...)
        <td>
          <xsl:call-template name="my-format">
            <xsl:with-param name="Val" select=" >>> data from <Reductions item> <<<"/>
            <xsl:with-param name="format" select="$DecPl2"/>
          </xsl:call-template>
        </td>

      </tr>
    </xsl:if>
  1. How can I call eg. Point/Grid/North item value from Reductions using ID parameter of PointRecord from FieldBook?

  2. How can I call PointRecord item from FieldBook using Point/ID item value from Reductions?


回答1:


I think you want to use a key; declare

<xsl:key name="red-ref" match="Reductions/Point" use="ID"/>

as a top-level element (i.e. a child of xsl:stylesheet or xsl:transform). Then, in any context you process a PointRecord element you can use key('red-ref', @ID) to find the referenced Point, i.e. key('red-ref', @ID)/Grid/North will give you that element.



来源:https://stackoverflow.com/questions/63262675/xslt-how-to-call-xml-item-without-id-partameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!