Last active
August 22, 2018 23:10
-
-
Save serkanberksoy/8dfcf73e60ead95f4e050e1685c7d61b to your computer and use it in GitHub Desktop.
Add a default valued node if that node does not exists in xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<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="/*"> | |
<xsl:copy> | |
<xsl:apply-templates /> | |
<xsl:if test="count(defaultx) = 0"> | |
<defaultx>||| DEFAULT VALUE FOR X |||</defaultx> | |
</xsl:if> | |
<xsl:if test="count(defaulty) = 0"> | |
<defaulty>||| DEFAULT VALUE FOR Y |||</defaulty> | |
</xsl:if> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> | |
<catalog> | |
<atag> | |
<btag attrib="attr">serkan</btag> | |
</atag> | |
<cd> | |
<title>Empire Burlesque</title> | |
<artist>Bob Dylan</artist> | |
<country>USA</country> | |
<company>Columbia</company> | |
<price>10.90</price> | |
<year>1985</year> | |
</cd> | |
<cd> | |
<title>Hide your heart</title> | |
<artist>Bonnie Tyler</artist> | |
<country>UK</country> | |
<company>CBS Records</company> | |
<price>9.90</price> | |
<year>1988</year> | |
</cd> | |
<defaulty>||| CUSTOM VALUE FOR Y |||</defaulty> | |
<cd> | |
<title>Greatest Hits</title> | |
<artist>Dolly Parton</artist> | |
<country>USA</country> | |
<company>RCA</company> | |
<price>9.90</price> | |
<year>1982</year> | |
</cd> | |
</catalog> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment