sri1209
asked on
removing the character from attribute values in xml through xslt
i have the below xml , need to change it to the result xml mentioned below, i have taken help from the forum members for the same earlier and have the following xslt(modified a bit to include additional tags), it is working fine to remove the the characters "\b." and "\b0". from Section[@type='Income']/Su mmary/Amou nt/@Name but not from
"Section[@type='Income']/S ummary/Per sons/Perso n/@Name , could you please let me know where am i going wrong on this ..? i need to change the characters in this particular "Section[@type='Income']" as i have similar tags with diff attribute names hat i need to keep it as is.
========xslt=========
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Correspondance/Ledg er/Section [@type='In come']">
<Income><xsl:apply-templat es select="@*|node()" /></Income>
</xsl:template>
<xsl:template match="Correspondance/Ledg er/Section [@type='Ex pense']">
<Expense><xsl:apply-templa tes select="@*|node()" /></Expense>
</xsl:template>
<xsl:template match="Correspondance/Ledg er/Section [@type='De duction']" >
<Deduction><xsl:apply-temp lates select="@*|node()" /></Deduction>
</xsl:template>
<xsl:template match="Section[@type='Inco me']/Summa ry/Amount/ @Name">
<xsl:attribute name="Name">
<xsl:call-template name="strip-name">
<xsl:with-param name="str" select="."></xsl:with-para m>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="strip-name">
<xsl:param name="str"/>
<xsl:value-of select="substring-before(s ubstring-a fter($str, '\b.'), '\b0.')"/>
</xsl:template>
<xsl:template match="Section[@type='Inco me']/Summa ry/Persons /Person/@N ame">
<xsl:attribute name="Name">
<xsl:call-template name="strip-name-inc">
<xsl:with-param name="str" select="."></xsl:with-para m>
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="strip-name-inc">
<xsl:param name="str1"/>
<xsl:value-of select="substring-before(s ubstring-a fter($str1 , '\b.'), '\b0.')"/>
</xsl:template>
</xsl:stylesheet>
========================== ========== ========== ========== ========== =======
========================
current xml
==========================
<Section type="Expense">
<SubDetails>
<Sub>
<HeaderLogo>d:\Apps\MCI\PR D\Adobe\Co rr\Logo\ic on_elig_bi lls.gif</H eaderLogo>
<Header>Expenses</Header>
<AssetSubHeader>Who has expenses?</AssetSubHeader>
<Caption>Who has expenses?</Caption>
<TotalText>Total expenses</TotalText>
<Month1>12/2014</Month1>
<Month2>01/2015</Month2>
</Sub>
</SubDetails>
<Persons>
<Person>
<Name>\b.GILBERTO\b0.</Nam e>
<Source>Goods, supplies and material cost</Source>
</Person>
<Person>
<Name>\b.GILBERTO\b0.</Nam e>
<Source>Other</Source>
</Person>
</Persons>
<Summary>
<Amount Name="\b.GILBERTO\b0." Source="Goods, supplies and material cost" Month="12/2014">29.17</Amo unt>
<Amount Name="\b.GILBERTO\b0." Source="Other" Month="12/2014">8.33</Amou nt>
<Amount Name="\b.GILBERTO\b0." Source="Goods, supplies and material cost" Month="01/2015">29.17</Amo unt>
<Amount Name="\b.GILBERTO\b0." Source="Other" Month="01/2015">8.33</Amou nt>
</Summary>
</Section>
need to remove the "\b." and "\b0." from the <Section type="Expense".
the result xml needs to be
<Section type="Expense">
<SubDetails>
<Sub>
<HeaderLogo>d:\Apps\MCI\PR D\Adobe\Co rr\Logo\ic on_elig_bi lls.gif</H eaderLogo>
<Header>Expenses</Header>
<AssetSubHeader>Who has expenses?</AssetSubHeader>
<Caption>Who has expenses?</Caption>
<TotalText>Total expenses</TotalText>
<Month1>12/2014</Month1>
<Month2>01/2015</Month2>
</Sub>
</SubDetails>
<Persons>
<Person>
<Name>GILBERTO</Name>
<Source>Goods</Source>
</Person>
<Person>
<Name>GILBERTO</Name>
<Source>Other</Source>
</Person>
</Persons>
<Summary>
<Amount Name="GILBERTO" Source="Goods" Month="12/2014">29.17</Amo unt>
<Amount Name="GILBERTO" Source="Other" Month="12/2014">8.33</Amou nt>
<Amount Name="GILBERTO" Source="Goods" Month="01/2015">29.17</Amo unt>
<Amount Name="GILBERTO" Source="Other" Month="01/2015">8.33</Amou nt>
</Summary>
</Section>
Thanks in advance
"Section[@type='Income']/S
========xslt=========
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Correspondance/Ledg
<Income><xsl:apply-templat
</xsl:template>
<xsl:template match="Correspondance/Ledg
<Expense><xsl:apply-templa
</xsl:template>
<xsl:template match="Correspondance/Ledg
<Deduction><xsl:apply-temp
</xsl:template>
<xsl:template match="Section[@type='Inco
<xsl:attribute name="Name">
<xsl:call-template name="strip-name">
<xsl:with-param name="str" select="."></xsl:with-para
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="strip-name">
<xsl:param name="str"/>
<xsl:value-of select="substring-before(s
</xsl:template>
<xsl:template match="Section[@type='Inco
<xsl:attribute name="Name">
<xsl:call-template name="strip-name-inc">
<xsl:with-param name="str" select="."></xsl:with-para
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="strip-name-inc">
<xsl:param name="str1"/>
<xsl:value-of select="substring-before(s
</xsl:template>
</xsl:stylesheet>
==========================
========================
current xml
==========================
<Section type="Expense">
<SubDetails>
<Sub>
<HeaderLogo>d:\Apps\MCI\PR
<Header>Expenses</Header>
<AssetSubHeader>Who has expenses?</AssetSubHeader>
<Caption>Who has expenses?</Caption>
<TotalText>Total expenses</TotalText>
<Month1>12/2014</Month1>
<Month2>01/2015</Month2>
</Sub>
</SubDetails>
<Persons>
<Person>
<Name>\b.GILBERTO\b0.</Nam
<Source>Goods, supplies and material cost</Source>
</Person>
<Person>
<Name>\b.GILBERTO\b0.</Nam
<Source>Other</Source>
</Person>
</Persons>
<Summary>
<Amount Name="\b.GILBERTO\b0." Source="Goods, supplies and material cost" Month="12/2014">29.17</Amo
<Amount Name="\b.GILBERTO\b0." Source="Other" Month="12/2014">8.33</Amou
<Amount Name="\b.GILBERTO\b0." Source="Goods, supplies and material cost" Month="01/2015">29.17</Amo
<Amount Name="\b.GILBERTO\b0." Source="Other" Month="01/2015">8.33</Amou
</Summary>
</Section>
need to remove the "\b." and "\b0." from the <Section type="Expense".
the result xml needs to be
<Section type="Expense">
<SubDetails>
<Sub>
<HeaderLogo>d:\Apps\MCI\PR
<Header>Expenses</Header>
<AssetSubHeader>Who has expenses?</AssetSubHeader>
<Caption>Who has expenses?</Caption>
<TotalText>Total expenses</TotalText>
<Month1>12/2014</Month1>
<Month2>01/2015</Month2>
</Sub>
</SubDetails>
<Persons>
<Person>
<Name>GILBERTO</Name>
<Source>Goods</Source>
</Person>
<Person>
<Name>GILBERTO</Name>
<Source>Other</Source>
</Person>
</Persons>
<Summary>
<Amount Name="GILBERTO" Source="Goods" Month="12/2014">29.17</Amo
<Amount Name="GILBERTO" Source="Other" Month="12/2014">8.33</Amou
<Amount Name="GILBERTO" Source="Goods" Month="01/2015">29.17</Amo
<Amount Name="GILBERTO" Source="Other" Month="01/2015">8.33</Amou
</Summary>
</Section>
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
figured it out now , thank you for the help.
welcome
ASKER
"Section[@type='Income']/S
the following xslt works fine to remove the "\b." and "\b0." from Section[@type='Income']/Su
current xslt:
========xslt=========
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Correspondance/Ledg
<Income><xsl:apply-templat
</xsl:template>
<xsl:template match="Correspondance/Ledg
<Expense><xsl:apply-templa
</xsl:template>
<xsl:template match="Correspondance/Ledg
<Deduction><xsl:apply-temp
</xsl:template>
<xsl:template match="Section[@type='Inco
<xsl:attribute name="Name">
<xsl:call-template name="strip-name">
<xsl:with-param name="str" select="."></xsl:with-para
</xsl:call-template>
</xsl:attribute>
</xsl:template>
-----this part of the xslt does not work it removes the whole <Name >tag from xml not from the value of the <Name>---
<xsl:template match="Section[@type='Inco
<xsl:attribute name="Name">
<xsl:call-template name="strip-name-inc">
<xsl:with-param name="str" select="."></xsl:with-para
</xsl:call-template>
</xsl:attribute>
</xsl:template>
<xsl:template name="strip-name">
<xsl:param name="str"/>
<xsl:value-of select="substring-before(s
</xsl:template>
</xsl:stylesheet>
Thank you .