I'm building a single XSL stylesheet to convert a number of XML files (each with a different root) to a set of divs for styling but I'm having problems with any template defined after the first, I know I'm doing something dumb/fundamentally wrong but I can't figure out what it is, so any advice would be appreciated.
I'm fairly sure this has asked before but after a few hours of searching I cannot find a result.
XML#1:
<domain:create xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>exampledomain.gtld</domain:name>
<domain:period unit="y">1</domain:period>
<domain:ns>
<domain:hostAttr>
<domain:hostName>ns1.exampledomain.gtld</domain:hostName>
<domain:hostAddr ip="v4">x.x.x.x</domain:hostAddr>
<domain:hostAddr ip="v4">y.y.y.y</domain:hostAddr>
<domain:hostAddr ip="v6">ff02::1</domain:hostAddr>
</domain:hostAttr>
<domain:hostAttr>
<domain:hostName>ns1.otherdomain.gtld</domain:hostName>
</domain:hostAttr>
</domain:ns>
<domain:registrant>RegistrantID</domain:registrant>
<domain:contact type="admin">AdminID</domain:contact>
<domain:contact type="tech">TechID</domain:contact>
<domain:contact type="billing">BillingID</domain:contact>
<domain:contact type="reseller">ResellerID</domain:contact>
<domain:authInfo>
<domain:pw>TransferPassword</domain:pw>
</domain:authInfo>
</domain:create>
XML#2
<domain:update xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
<domain:name>exampledomain.gtld</domain:name>
<domain:add>
<domain:ns>
<domain:hostAttr>
<domain:hostName>ns1.exampledomain.gtld</domain:hostName>
<domain:hostAddr ip="v4">1.1.1.1</domain:hostAddr>
</domain:hostAttr>
</domain:ns>
<domain:contact type="tech">NewTechID</domain:contact>
<domain:status s="clientHold">Payment overdue.</domain:status>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostAttr>
<domain:hostName>ns1.otherdomain.gtld</domain:hostName>
</domain:hostAttr>
</domain:ns>
<domain:status s="clientTransferProhibited"/>
</domain:rem>
<domain:chg>
<domain:registrant>NewRegistrantID</domain:registrant>
<domain:authInfo>
<domain:pw>NewPassword</domain:pw>
</domain:authInfo>
</domain:chg>
</domain:update>
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<xsl:variable name="vLower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="vUpper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="name() = 'domain:update'">
<xsl:call-template name="domain_update"/>
</xsl:when>
<xsl:otherwise test="name() = 'domain:create'">
<xsl:call-template name="domain_create"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="domain_update">
<div class="action">Domain Update: '<xsl:value-of select="domain:name"/>'</div>
<div class="attributes">
<xsl:for-each select="domain:ns/domain:hostAttr">
<div class="hostname">Nameserver: <xsl:value-of select="domain:hostName"/>
<xsl:for-each select="domain:hostAddr">
<div>
<xsl:attribute name="class"><xsl:value-of select="@ip"/>_address</xsl:attribute>
IP<xsl:value-of select="@ip"/> Glue: <xsl:value-of select="."/>
</div>
</xsl:for-each>
</div>
</xsl:for-each>
</div>
<div class="contacts">
<div class="contact_registrant">Registrant: <xsl:value-of select="domain:registrant"/></div>
<xsl:for-each select="domain:contact">
<div>
<xsl:attribute name="class">contact_<xsl:value-of select="@type"/></xsl:attribute>
<xsl:value-of select="concat(translate(substring(@type,1,1), $vLower, $vUpper), substring(@type, 2), substring('', 1 div not(position()=last())))"/>: <xsl:value-of select="."/>
</div>
</xsl:for-each>
</div>
<div class="password">
</xsl:template>
<xsl:template name="domain_create">
<div class="action">Domain Create: '<xsl:value-of select="domain:name"/>' for a period of <xsl:value-of select="domain:period"/> <xsl:value-of select="domain:period/@unit"/></div>
<div class="attributes">
<xsl:for-each select="domain:ns/domain:hostAttr">
<div class="hostname">Nameserver: <xsl:value-of select="domain:hostName"/>
<xsl:for-each select="domain:hostAddr">
<div>
<xsl:attribute name="class"><xsl:value-of select="@ip"/>_address</xsl:attribute>
IP<xsl:value-of select="@ip"/> Glue: <xsl:value-of select="."/>
</div>
</xsl:for-each>
</div>
</xsl:for-each>
</div>
<div class="contacts">
<div class="contact_registrant">Registrant: <xsl:value-of select="domain:registrant"/></div>
<xsl:for-each select="domain:contact">
<div>
<xsl:attribute name="class">contact_<xsl:value-of select="@type"/></xsl:attribute>
<xsl:value-of select="concat(translate(substring(@type,1,1), $vLower, $vUpper), substring(@type, 2), substring('', 1 div not(position()=last())))"/>: <xsl:value-of select="."/>
</div>
</xsl:for-each>
</div>
<div class="password">
</xsl:template>
</xsl:stylesheet>
Using XML#1 produces no output (where i believe it should) but using XML#2 does as it's required. If I swap the named templates then it works.
No comments:
Post a Comment