PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 23, 2022

[FIXED] How to change get third position of string on XML (Using substring)

 August 23, 2022     feed, magento2, xml, xslt     No comments   

Issue

I'm trying to generate a product feed with Xtento Product export on magento and I can't get the product_type to show the value of the third position.

Can you give me a hand with this?

The code:

<!--product_type -->
            <xsl:element name="product_type">
                <xsl:choose>
                 <xsl:when test="string(xtento_mapped_category)"><xsl:value-of select="xtento_mapped_category"/></xsl:when> 
                <xsl:when test="string(cats/cat[children_count=0]/path_name)">
                <xsl:value-of select="substring-after(substring-after(cats/cat[children_count=0]/path_name,'>'),' > ')" />
                </xsl:when>
                <xsl:otherwise>
                <xsl:value-of select="substring-after(substring-after(parent_item/cats/cat[children_count=0]/path_name,'>'),' > ')" />
                </xsl:otherwise>
                </xsl:choose>
            </xsl:element>

Output product_type: Women > Undies > Thong Underwear > Cotton Thong Underwear

It should be just "Thong Underwear" or the 3rth position of the string.


Solution

Given a string that contains:

alpha > bravo > charlie > delta

the following expression:

<xsl:value-of select="substring-before(substring-after(substring-after($your-string, ' > '), ' > '), ' > ')" />

will return:

charlie

Note that this assumes that the third token is not the last token of the given string. If you cannot be sure of that, then use:

<xsl:value-of select="substring-before(substring-after(substring-after(concat($your-string, ' > '), ' > '), ' > '), ' > ')" />


Answered By - michael.hor257k
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing