It has been few years since I last played around with XSLT and XPath, so it actually took me almost an hour to make this crude proof of concept:
This piece of code first copies all elements to the output file and then processes the Stat elements via <xsl:choose> and <xsl:when> methods and creates new element named as Strength etc.
I'm still checking how can I make the creation of stats completely automated but current version is easy enough to expand via use of copy-paste.
If you want the "new" elements named in some other way, now is good time to say it
Note: heavily edited from first version
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="/"></xsl:copy-of>
<xsl:for-each select="D20Character/CharacterSheet/StatBlock/Stat">
<xsl:choose>
<xsl:when test="@name = 'Strength'">
<xsl:element name="{@name}">
<xsl:attribute name="value">
<xsl:value-of select="@value"></xsl:value-of>
</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="@name = 'Constitution'">
<xsl:element name="{@name}">
<xsl:attribute name="value">
<xsl:value-of select="@value"></xsl:value-of>
</xsl:attribute>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This piece of code first copies all elements to the output file and then processes the Stat elements via <xsl:choose> and <xsl:when> methods and creates new element named as Strength etc.
I'm still checking how can I make the creation of stats completely automated but current version is easy enough to expand via use of copy-paste.
If you want the "new" elements named in some other way, now is good time to say it
Note: heavily edited from first version
Last edited: