简体   繁体   中英

XSLT get node at same level of for-each

I'm trying to get data from a node that is on the same level as the node I'm using for a for-each. How do I get the DTM nodes to return data while I am in the SVC for-each?

I thought add "/" would send me up a level but it's not working. I also thought "//" might work but that doesn't work either.

Here is my XML:

<Loop2110>
              <SVC>
                <C003_1>
                  <F235>HC</F235>
                  <F234_1>99214</F234_1>
                </C003_1>
                <F782_1>100</F782_1>
                <F782_2>75</F782_2>
                <F380_1>1</F380_1>
              </SVC>
              <DTM>
                <F374>472</F374>
                <F373>2021-03-01</F373>
              </DTM>
              <CAS>
                <F1033>PR</F1033>
                <F1034_1>3</F1034_1>
                <F782_1>45</F782_1>
              </CAS>
              <CAS>
                <F1033>CO</F1033>
                <F1034_1>45</F1034_1>
                <F782_1>99.54</F782_1>
              </CAS>
              <REF>
                <F128>6R</F128>
                <F127>1</F127>
              </REF>
              <AMT>
                <F522>B6</F522>
                <F782>100.46</F782>
              </AMT>
</Loop2110>

Here is my XSLT:

<xsl:for-each select="SVC">
                    <TR style="background-color: B4D1DC">
                        <TD>
                            <xsl:choose>
                                <xsl:when test="/DTM[F374='472'][1]/F373[1] = ''">
                                    &#160;  
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="/DTM/F374[1]/F373[1]"/>
                                </xsl:otherwise>
                            </xsl:choose>       
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="/DTM[F374='150'][1]/F373[1] = ''">
                                    &#160;  
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="/DTM/F374[1]/F373[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD><xsl:value-of select="C003_1[1]/F234_1[1]"/></TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="C003_1[1]/F1339_1[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="C003_1[1]/F1339_1[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="C003_1[1]/F1339_2[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="C003_1[1]/F1339_2[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="C003_1[1]/F1339_3[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="C003_1[1]/F1339_3[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="C003_1[1]/F1339_4[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="C003_1[1]/F1339_4[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="F782_1[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="F782_1[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="F782_2[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="F782_2[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="@PaidAmount=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="AMT/@Amount"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                        <TD>
                            <xsl:choose>
                                <xsl:when test="F380_1[1]=''">
                                    &#160;
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="F380_1[1]"/>
                                </xsl:otherwise>
                            </xsl:choose> 
                        </TD>
                    </TR>
                </xsl:for-each>

if you are in the context of SVC , then the expression ../DTM will select the sibling DTM node (or nodes, if there are more than one).

Alternatively, you could use following-sibling::DTM - but this assumes the nodes are in the order shown in your example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM