Concat 2 element's values and revise them
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 4
- Joined: Fri Jul 02, 2021 6:30 pm
Concat 2 element's values and revise them
Hi community, new here but it seems I will stay for long!
Can someone help me if I can do "Concat 2 element's values and revise them" with XPATH refactoring?
before:
after:
Can someone help me if I can do "Concat 2 element's values and revise them" with XPATH refactoring?
before:
Code: Select all
<category id="1214554589" name="Cell phone screwdrivers"/>
<category_idosell id="2898" path="Hardware > Tools"/>
Code: Select all
<category name="Hardware///Tools///Cell phone screwdrivers" />
-
- Posts: 159
- Joined: Mon Nov 24, 2014 1:49 pm
- Location: Greven/Germany
Re: Concat 2 element's values and revise them
Hi s0n1k,
you can use this snippet:
you can use this snippet:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<xsl:element name="category">
<xsl:attribute name="name">
<xsl:value-of select="substring-before(//category_idosell[1]/@path, ' > ')"/>
<xsl:value-of select="'///'"/>
<xsl:value-of select="substring-after(//category_idosell[1]/@path, ' > ')"/>
<xsl:value-of select="'///'"/>
<xsl:value-of select="//category[1]/@name"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
stefan-jung.org – Your DITA/DITA-OT XML consultant
-
- Posts: 4
- Joined: Fri Jul 02, 2021 6:30 pm
Re: Concat 2 element's values and revise them
at your code I get an error:
Code: Select all
A sequence of more than one item is not allowed as the first argument of fn:substring-before() ("Hardware > Tools", "Hardware > Tools")
-
- Posts: 4
- Joined: Fri Jul 02, 2021 6:30 pm
Re: Concat 2 element's values and revise them
ok, got it. I have tested at only one <product> .... </product> and it worked. Just it deleted everything and got the category result only.
Can you show me the way on how to apply this snippet at an XML file that contains 1000 <product> .. </products> and I want to get the same products just the only change to be the category element with the newly created value for each product?
thank you in advance for your time!
Code: Select all
<?xml version="1.0" encoding="UTF-8"?><category name="Hardware///Tools///Cell phone screwdrivers"/>
thank you in advance for your time!
-
- Posts: 4
- Joined: Fri Jul 02, 2021 6:30 pm
Re: Concat 2 element's values and revise them
it seems I am close to a solution. I found a code but it only outputs the 1st node.
How can I make it loop through all nodes and apply the snippet?
My code now
How can I make it loop through all nodes and apply the snippet?
My code now
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="category/@name">
<xsl:element name="category">
<xsl:attribute name="name">
<xsl:value-of select="substring-before(//category_idosell[1]/@path, ' > ')"/>
<xsl:value-of select="'///'"/>
<xsl:value-of select="substring-after(//category_idosell[1]/@path, ' > ')"/>
<xsl:value-of select="'///'"/>
<xsl:value-of select="//category[1]/@name"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 159
- Joined: Mon Nov 24, 2014 1:49 pm
- Location: Greven/Germany
Re: Concat 2 element's values and revise them
You match on category/@name. Maybe this is not what you want to do. Probably you need an <xsl:apply-templates/> somewhere. Difficult to say without seeing your full code.
stefan-jung.org – Your DITA/DITA-OT XML consultant
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service