0
<Products xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" 
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

<Product>
<status>1</status> 
<ProductName>******************</ProductName> 
<model>******************</model>
<ProductQTY>******************</ProductQTY> 
<CostPrice>******************</CostPrice>
<RetailPrice>******************</RetailPrice> 
<FullCategoryPath>******************</FullCategoryPath>
<description> 
<![CDATA[******************
]]></description> 
<image_link>https://******************</image_link> 
</Product>
<Product>
<status>1</status>
<ProductName>******************</ProductName>
<model>******************7</model>
<ProductQTY>0</ProductQTY> 
<CostPrice>1******************</CostPrice>
<RetailPrice>141.9</RetailPrice> 
<FullCategoryPath>******************</FullCategoryPath><description> 
<![CDATA******************
  ]]></description> 
<image_link>https://******************</image_link>
</Product>
</Products>    <!-- Added by edit -->

as you see above.
How can I fix my XSLT file?

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
            xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" 
            xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"               
            exclude-result-prefixes="sitemap image">

    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node() "/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*">
        <xml>
            <xsl:for-each select="node()">
                <xsl:choose >
                    <xsl:when test="node() | model !=''">
                        <Product>     
                            <xsl:apply-templates select="@* | node() "/>
                            <SProductCode >
                                <xsl:value-of select="node() | @model" />
                            </SProductCode>
                            <CategoryName>
                                <value-of select=""/>
                            </CategoryName>
                            .
                            .
                            .
                            .
                        </Product>
                    </xsl:when>
                </xsl:choose>
            </xsl:for-each>
        </xml>
    </xsl:template>
</xsl:stylesheet>    <!-- Added by edit -->

For example:
How can I show category names product name ex. from my node(). I can't parse them.

xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"

These two namespaces ruin me so badly.They are inside of my root element"Products".

Output is: All values are false .

<xml>
     <Product>
       <SProductCode>1</SProductCode>
       <CategoryName>
         <value-of select="node() | @model" />
       </CategoryName>
     </Product>
     <Product>
       <SProductCode>1</SProductCode>
       <CategoryName>
         <value-of select="node() | @model" />
       </CategoryName>
     </Product>

What am I gonna write for "SProductCode" or"CategoryName" to properly run it?

Utku Yıldız
  • 33
  • 2
  • 9
  • In the result do appear only `SProductCode>` and `CategoryName` elements with values beside empty `` nodes. Is it possible that you gave a partial output as input XML in your question? – zx485 Sep 24 '18 at 13:27
  • The namespaces listed in the XML are not actually used anywhere (all the elements in your XML are not in any namespaces) so they shouldn't actually cause a problem in this instance. – Tim C Sep 24 '18 at 13:34
  • @zx485 Output added – Utku Yıldız Sep 24 '18 at 14:29
  • @timc if ı write a normal xslt , Im getting null xml because sitemap and image block to list it . – Utku Yıldız Sep 24 '18 at 14:41
  • I still don't understand what you're trying to achieve. Is this the desired output? When I apply the stylesheet, I get a different output. And in what way is that problem related to the namespaces, because, as @TimC wrote, they are unused in the XML? – zx485 Sep 24 '18 at 14:48
  • @zx485 My output should be like filled , filled ,and other Properties filled with data from my received XML source.As you show First Product xml ,xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" These 2 xmlns unfortunately prevent my output.Thanks for your struggles. – Utku Yıldız Sep 24 '18 at 15:16
  • If you're just removing namespaces, see https://stackoverflow.com/questions/5268182/how-to-remove-namespaces-from-xml-using-xslt – William Walseth Sep 24 '18 at 15:22

1 Answers1

0

The following modified template approaches your desired output. I removed some unnecessary code, but I couldn't derive which values you want to put into the xsl:value-of select="..." />. I also changed your xsl:choose to a simple predicate of the Product xsl:for-each loop.

<xsl:template match="/Products">
    <xml>
        <xsl:for-each select="Product[model != '']">
            <Product>     
                <SProductCode >
                    <xsl:value-of select="model" />
                </SProductCode>
                <CategoryName>
                    <xsl:value-of select="FullCategoryPath"/>
                </CategoryName>
                .
                .
                .
                .
            </Product>
        </xsl:for-each>
    </xml>
</xsl:template>

Output is:

<xml>
    <Product>
        <SProductCode>******************</SProductCode>
        <CategoryName>******************</CategoryName>
        .
        .
        .
        .
    </Product>
    <Product>
        <SProductCode>******************7</SProductCode>
        <CategoryName>******************</CategoryName>
        .
        .
        .
        .
    </Product>
</xml>
zx485
  • 28,498
  • 28
  • 50
  • 59
  • ı put breakpoint to check then it's not enter the . So they are not getting my Product attributes like SProductCode,CategoryName... – Utku Yıldız Sep 24 '18 at 15:45
  • Of course you can (and must) adjust the `match` rule to the actual design of your full XML. It could be simply `Products` instead, for example. – zx485 Sep 24 '18 at 15:52
  • I tried almost all posibilities and again null.I can't take right values from xml and parse them in my xml attributes. – Utku Yıldız Sep 26 '18 at 08:49