Member Avatar for manowar83

Hi, everybody!
I want to know if there is a way to resolve my problem.
So I want with xpath to get only nodes without their child nodes.
My xml is:

<ts>
<uc>
    <Questions>
        <q  />
        <q  />
    </Questions>
</uc>
<uc>
    <Questions>
        <q  />
        <q  />
        <q  />
    </Questions>
</uc>
</ts>
So I want the following result:
<ts>
<uc>
</uc>
<uc>
</uc>
</ts>

As you see I want only uc nodes without their children Question nodes.
I need an urgent help.
So any your answer would be highly appreciated by me.
Thanks in advance!

Recommended Answers

All 2 Replies

one way ...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" />

<xsl:template match="/ts">
   <ts>
   <xsl:apply-templates />
   </ts>
</xsl:template>

<xsl:template match="uc">
    <uc>
    </uc>
</xsl:template>

</xsl:stylesheet>

Hi, everybody!
I want to know if there is a way to resolve my problem.
So I want with xpath to get only nodes without their child nodes.
My xml is:

<ts>
<uc>
    <Questions>
        <q  />
        <q  />
    </Questions>
</uc>
<uc>
    <Questions>
        <q  />
        <q  />
        <q  />
    </Questions>
</uc>
</ts>
So I want the following result:
<ts>
<uc>
</uc>
<uc>
</uc>
</ts>

As you see I want only uc nodes without their children Question nodes.
I need an urgent help.
So any your answer would be highly appreciated by me.
Thanks in advance!

here is the code:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="uc">
<uc><xsl:apply-templates/></uc>
</xsl:template>
<xsl:template match="ts">
<ts><xsl:apply-templates/></ts>
</xsl:template>

<xsl:template match="uc/text()">
<xsl:value-of select="normalize(.)"/>
</xsl:template>
<xsl:template match="uc/*">
</xsl:template>
</xsl:stylesheet>

<xsl:template match="*"></xsl:template>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.