不使用xsl获取xml的多个值

不使用xsl获取xml的多个值,xml,xslt,Xml,Xslt,我有这样的xml <categories> <category> <Loc>India</Loc> <Loc>US</Loc> <Loc>Spain</Loc> <type>A</type> <type>B</type> <Cat>unknown</Cat> <Su

我有这样的xml

<categories>
  <category>
    <Loc>India</Loc>
    <Loc>US</Loc>
    <Loc>Spain</Loc>
    <type>A</type>
    <type>B</type>
    <Cat>unknown</Cat>
    <SubCat>True</SubCat>
  </category>
</categories>

印度
美国
西班牙
A.
B
未知的
真的
在我的xsl中

<xsl:for-each select="categories/category">
All locations:<xsl:value-of select="Loc"/>
All type: <xsl:value-of select="type"/> 
</xsl:for-each>

所有地点:
所有类型:
我得到的结果是 所有地点:印度 所有类型:A 我想让它得到Loc和type的所有值 所有地点:印度、美国、西班牙 所有类型:A、B

你能告诉我哪里出错了吗

谢谢,

试试这个:

<xsl:for-each select="categories/category">
    All locations:
    <xsl:for-each select="Loc">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">, </xsl:if>
    </xsl:for-each>
    <br />
    All type:
    <xsl:for-each select="type">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">, </xsl:if>
    </xsl:for-each>
    <br />
</xsl:for-each>

所有地点:
, 

所有类型: ,
编辑:注意您的XML示例格式不正确,因为您得到了一个不匹配的
标记。

请尝试以下操作:

<xsl:for-each select="categories/category">
    All locations:
    <xsl:for-each select="Loc">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">, </xsl:if>
    </xsl:for-each>
    <br />
    All type:
    <xsl:for-each select="type">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">, </xsl:if>
    </xsl:for-each>
    <br />
</xsl:for-each>

所有地点:
, 

所有类型: ,

编辑:注意您的XML示例格式不正确,因为您得到了一个不匹配的
标记。

一个解决方案是合并模板:

<xsl:template match="categories/category">
  <xsl:text>All locations: </xsl:text>
  <xsl:apply-templates select="Loc" mode="list" />
  <xsl:text>All type: </xsl:text>
  <xsl:apply-templates select="type" mode="list" />
</xsl:template>

<xsl:template match="*" mode="list">
  <xsl:value-of select="." />
  <xsl:if test="position() != last()">, </xsl:if>
  <xsl:if test="position() = last()">&#10;</xsl:if><!-- line feed -->
</xsl:template>

所有地点:
所有类型:
, 



一种解决方案是合并模板:

<xsl:template match="categories/category">
  <xsl:text>All locations: </xsl:text>
  <xsl:apply-templates select="Loc" mode="list" />
  <xsl:text>All type: </xsl:text>
  <xsl:apply-templates select="type" mode="list" />
</xsl:template>

<xsl:template match="*" mode="list">
  <xsl:value-of select="." />
  <xsl:if test="position() != last()">, </xsl:if>
  <xsl:if test="position() = last()">&#10;</xsl:if><!-- line feed -->
</xsl:template>

所有地点:
所有类型:
,