xml - update the attribute name and element value -
i need update address address line 1 , value inside 1 jane place , save in variable. input dummy xml
used stylesheet
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema"> <xsl:template match="/"> <xsl:variable name="request"> <customers> <customer name="address">1 doe place</customer> <customer name="state">oh</customer> <customer name="name">john</customer> <customer name="name">kevin</customer> <customer name="name">leon</customer> <customer name="name">adam</customer> <customer name="city">columbus</customer> </customers> </xsl:variable> <xsl:variable name="response"> ------- </xsl:variable> <xsl:copy-of select="$response"/> </xsl:template> </xsl:stylesheet>
dont know update here. know how identity transform here i'm confused
perhaps work (i still puzzled regarding about):
xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:variable name="request"> <customers> <customer name="address">1 doe place</customer> <customer name="state">oh</customer> <customer name="name">john</customer> <customer name="name">kevin</customer> <customer name="name">leon</customer> <customer name="name">adam</customer> <customer name="city">columbus</customer> </customers> </xsl:variable> <xsl:variable name="response"> <customers> <xsl:for-each select="exsl:node-set($request)/customers/customer"> <xsl:choose> <xsl:when test="@name='address'"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:text>1 jane place</xsl:text> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:copy-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </customers> </xsl:variable> <xsl:template match="/"> <xsl:copy-of select="$response"/> </xsl:template> </xsl:stylesheet>
the result, when applied xml input:
<?xml version="1.0" encoding="utf-8"?> <customers> <customer name="address">1 jane place</customer> <customer name="state">oh</customer> <customer name="name">john</customer> <customer name="name">kevin</customer> <customer name="name">leon</customer> <customer name="name">adam</customer> <customer name="city">columbus</customer> </customers>
Comments
Post a Comment