xml - Concatenate multiple attributes in one with XSL -
i have input xml looks following.
<?xml version="1.0" encoding="utf-8"?> <topic title="my topic" subtopic="my subtopic"> <table title="my table" media="print" role="center"> <thead></thead> <tbody></tbody> </table> </topic> i want translated xsl following.
<?xml version="1.0" encoding="utf-8"?> <topic title="my topic" subtitle="my subtopic"> <table title="my table" outputclass="print center"> <thead></thead> <tbody></tbody> </table> </topic> if notice other attribute of table must concatenated in 1 attribute named outputclass other attribute of table not of topic.
i have xsl -
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" exclude-result-prefixes="xsl xsi"> <xsl:output method="xml" indent="yes" omit-xml-declaration="no" standalone="no" doctype-public="-//oasis//dtd dita composite//en" doctype-system="topic.dtd"/> <!-- generic element --> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <xsl:template match="table"> <table> <xsl:apply-templates select="@role | @media" mode="table.att"/> <xsl:apply-templates select="@*"/> <xsl:apply-templates /> </table> </xsl:template> <xsl:template match="@*"> <xsl:if test="local-name(.)!='nonamespaceschemalocation'"> <xsl:attribute name="{local-name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="@*" mode="table.att"> <xsl:choose> <xsl:when test="local-name() = 'role'"> <xsl:attribute name="outputclass"> <xsl:value-of select="."></xsl:value-of> </xsl:attribute> </xsl:when> <xsl:otherwise> <!-- <xsl:apply-templates select="."/> --> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> as expected, doesn't trick. please me this. think need send attributes in order concatenate not sure how that.
try this
<xsl:template match="table"> <table> <xsl:apply-templates select="@title"/> <xsl:if test="@role , @media"> <xsl:attribute name="outputclass"> <xsl:value-of select="concat(@media, ' ', @role)"/> </xsl:attribute> </xsl:if> <xsl:apply-templates /> </table> </xsl:template>
Comments
Post a Comment