XSLT 中的嵌套循环

发布于 2024-10-30 22:38:41 字数 4432 浏览 3 评论 0 原文

我尝试在 XSL 文件中执行嵌套循环,但在多次尝试后卡住了

我的 xml 文件是这样的

<chromosome cnumber="X" cstart="10000" cend="1000000">
    <gene>
        <gname>ENSG00000216667</gname>
        <gstart>100411</gstart>
        <gend>102713</gend>
        <external_ref>
            <one>OTTG:OTTHUMG00000046372</one>
            <two>HGNC:CXYorf11</two>
            <three>HGNC_curated_gene:CXYorf11</three>
        </external_ref>
        <transcript>
            <tname>ENST00000406851</tname>
            <tstart>100411</tstart>
            <tend>102713</tend>
            <tstrand>+1</tstrand>
        </transcript>
    </gene>
    <gene>
        <gname>ENSG00000182378</gname>
        <gstart>122990</gstart>
        <gend>150024</gend>
        <external_ref>
            <one>UCSC:uc004cpa.1</one>
            <two>UCSC:uc004cpb.1</two>
            <three>HGNC:PLCXD1</three>
            <four>HGNC_automatic_gene:PLCXD1</four>
        </external_ref>
        <transcript>
            <tname>ENST00000381657</tname>
            <tstart>127860</tstart>
            <tend>150024</tend>
            <tstrand>+1</tstrand>
        </transcript>
        <transcript>
            <tname>ENST00000399012</tname>
            <tstart>122990</tstart>
            <tend>150021</tend>
            <tstrand>+1</tstrand>
        </transcript>
        <transcript>
            <tname>ENST00000381663</tname>
            <tstart>122992</tstart>
            <tend>150021</tend>
            <tstrand>+1</tstrand>
        </transcript>
    </gene>
    <gene>
        <gname>ENSG00000214798</gname>
        <gstart>148481</gstart>
        <gend>149027</gend>
        <external_ref>
            <one>UCSC:uc004cpc.1</one>
            <two>Clone_based_ensembl_gene:BX000483.7</two>
        </external_ref>
        <transcript>
            <tname>ENST00000399005</tname>
            <tstart>148481</tstart>
            <tend>149027</tend>
            <tstrand>+1</tstrand>
        </transcript>
    </gene>
    <gene>
        <gname>ENSG00000178605</gname>
        <gstart>150026</gstart>
        <gend>160887 </gend>
        <external_ref>
            <one>UCSC:uc004cpe.1</one>
            <two>HGNC:GTPBP6</two>
            <three>HGNC_automatic_gene:GTPBP6</three>
        </external_ref>
        <transcript>
            <tname>ENST00000326153</tname>
            <tstart>150026</tstart>
            <tend>160887</tend>
            <tstrand>-1</tstrand>
        </transcript>
    </gene>
    <gene>

我在这里尝试了 XSLT 这种方式

<xsl:for-each select="chromosome/gene">
    Name: <xsl:value-of select="gname" /> <br />
    Start Region: <xsl:value-of select="gstart" /> <br />
    End Region: <xsl:value-of select="gend" /> <br /> 
    <xsl:value-of select="external_ref/one "/><br />
    <xsl:value-of select="external_ref/two "/>
    <xsl:if test="external_ref/three !=' '"><br/>
        <xsl:value-of select="external_ref/three "/>
    </xsl:if>
    <xsl:if test="external_ref/four !=' '"><br/>
        <xsl:value-of select="external_ref/four "/>
    </xsl:if>
    <xsl:for-each select="chromosome/gene/transcript">
        Name:<xsl:value-of select="tname" /></strong> <br />
        Start Region: <xsl:value-of select="tstart" /> <br />
        End Region: <xsl:value-of select="tend" /> <br />
        Strand: <xsl:value-of select="tstrand" />
    </xsl:for-each>
</xsl:for-each>

问题是我没有得到任何成绩单;当我在顶部的每个循环只使用一个时,我只从 xml 列表中得到一份不完整的记录,

你们能指出我的错误吗,我对 XSLT 完全陌生。

谢谢

I have tried to perform nested loop in the XSL file but got stuck after several attempt

My xml file goes like this way

<chromosome cnumber="X" cstart="10000" cend="1000000">
    <gene>
        <gname>ENSG00000216667</gname>
        <gstart>100411</gstart>
        <gend>102713</gend>
        <external_ref>
            <one>OTTG:OTTHUMG00000046372</one>
            <two>HGNC:CXYorf11</two>
            <three>HGNC_curated_gene:CXYorf11</three>
        </external_ref>
        <transcript>
            <tname>ENST00000406851</tname>
            <tstart>100411</tstart>
            <tend>102713</tend>
            <tstrand>+1</tstrand>
        </transcript>
    </gene>
    <gene>
        <gname>ENSG00000182378</gname>
        <gstart>122990</gstart>
        <gend>150024</gend>
        <external_ref>
            <one>UCSC:uc004cpa.1</one>
            <two>UCSC:uc004cpb.1</two>
            <three>HGNC:PLCXD1</three>
            <four>HGNC_automatic_gene:PLCXD1</four>
        </external_ref>
        <transcript>
            <tname>ENST00000381657</tname>
            <tstart>127860</tstart>
            <tend>150024</tend>
            <tstrand>+1</tstrand>
        </transcript>
        <transcript>
            <tname>ENST00000399012</tname>
            <tstart>122990</tstart>
            <tend>150021</tend>
            <tstrand>+1</tstrand>
        </transcript>
        <transcript>
            <tname>ENST00000381663</tname>
            <tstart>122992</tstart>
            <tend>150021</tend>
            <tstrand>+1</tstrand>
        </transcript>
    </gene>
    <gene>
        <gname>ENSG00000214798</gname>
        <gstart>148481</gstart>
        <gend>149027</gend>
        <external_ref>
            <one>UCSC:uc004cpc.1</one>
            <two>Clone_based_ensembl_gene:BX000483.7</two>
        </external_ref>
        <transcript>
            <tname>ENST00000399005</tname>
            <tstart>148481</tstart>
            <tend>149027</tend>
            <tstrand>+1</tstrand>
        </transcript>
    </gene>
    <gene>
        <gname>ENSG00000178605</gname>
        <gstart>150026</gstart>
        <gend>160887 </gend>
        <external_ref>
            <one>UCSC:uc004cpe.1</one>
            <two>HGNC:GTPBP6</two>
            <three>HGNC_automatic_gene:GTPBP6</three>
        </external_ref>
        <transcript>
            <tname>ENST00000326153</tname>
            <tstart>150026</tstart>
            <tend>160887</tend>
            <tstrand>-1</tstrand>
        </transcript>
    </gene>
    <gene>

Here I tried XSLT this way

<xsl:for-each select="chromosome/gene">
    Name: <xsl:value-of select="gname" /> <br />
    Start Region: <xsl:value-of select="gstart" /> <br />
    End Region: <xsl:value-of select="gend" /> <br /> 
    <xsl:value-of select="external_ref/one "/><br />
    <xsl:value-of select="external_ref/two "/>
    <xsl:if test="external_ref/three !=' '"><br/>
        <xsl:value-of select="external_ref/three "/>
    </xsl:if>
    <xsl:if test="external_ref/four !=' '"><br/>
        <xsl:value-of select="external_ref/four "/>
    </xsl:if>
    <xsl:for-each select="chromosome/gene/transcript">
        Name:<xsl:value-of select="tname" /></strong> <br />
        Start Region: <xsl:value-of select="tstart" /> <br />
        End Region: <xsl:value-of select="tend" /> <br />
        Strand: <xsl:value-of select="tstrand" />
    </xsl:for-each>
</xsl:for-each>

The problem is I am not getting any transcript; when I use only one for each loop at the top then I get only one transcript not whole from the xml list

Can you guys point my mistake, I am completely new to XSLT.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2024-11-06 22:38:41

通过外部 循环,您已经处于染色体/基因级别。将其视为文件系统中的“更改为该目录”。

当您想要从其中获取转录本时,您只需选择以下选项:

<xsl:for-each select="transcript">

With the outer <xsl:for-each loop you already stand at the level of chromosome/gene. Think of it as in "changing into that directory" in a file system.

When you want the transcript from within there, you need to only select this like:

<xsl:for-each select="transcript">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文