diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-09-24 04:28:45 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-09-24 04:28:45 +0200 |
commit | 08a01723af9cd52c078d5ca6c38c34d375b39fa0 (patch) | |
tree | 6eadea9c67f4bb56a9e4ee09f4982efaf61deece /misc/xml | |
parent | 924adedb2928f5657c6668f606dbb3294b3c45da (diff) | |
parent | ae7f83a7948d8c3760f8019899a45e6ec90c2c6a (diff) | |
download | pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.gz pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.bz2 pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.xz pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.zip |
Finalyze XML support and provide initial support for views (only descriptions so far)
Diffstat (limited to 'misc/xml')
-rwxr-xr-x | misc/xml/format.sh | 8 | ||||
-rw-r--r-- | misc/xml/format.xsl | 44 | ||||
-rw-r--r-- | misc/xml/update_to_new_format.xsl | 118 |
3 files changed, 170 insertions, 0 deletions
diff --git a/misc/xml/format.sh b/misc/xml/format.sh new file mode 100755 index 0000000..c522f44 --- /dev/null +++ b/misc/xml/format.sh @@ -0,0 +1,8 @@ +#! /bin/bash + +if [ -z "$1" ]; then + echo "Usage: $0 [ xml_file ]" + exit 0 +fi + +cat $1 | xmllint -format - | xsltproc format.xsl - diff --git a/misc/xml/format.xsl b/misc/xml/format.xsl new file mode 100644 index 0000000..92abcbb --- /dev/null +++ b/misc/xml/format.xsl @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + <xsl:template match="register|field"> + <xsl:if test="local-name() = 'field'"> + <xsl:value-of select="preceding-sibling::text()"/> + </xsl:if> + + <xsl:element name="{local-name()}"> + <xsl:apply-templates select="@*"/> + <xsl:for-each select="view"> + <xsl:copy> + <xsl:apply-templates select="@*"/> + </xsl:copy> + </xsl:for-each> + <xsl:apply-templates select="field"/> + <xsl:if test="field"> + <xsl:value-of select="text()[last()]"/> + </xsl:if> + </xsl:element> + </xsl:template> + + <xsl:template match="//model/bank|//model/transform|//model/enum|//model/unit"> + <xsl:value-of select="preceding-sibling::text()"/> + <xsl:copy> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> + </xsl:template> + + <xsl:template match="model"> + <xsl:copy> + <xsl:apply-templates select="bank"/> + <xsl:apply-templates select="transform"/> + <xsl:apply-templates select="enum"/> + <xsl:apply-templates select="unit"/> + <xsl:value-of select="text()[last()]"/> + </xsl:copy> + </xsl:template> + + <xsl:template match="@*|node()"> + <xsl:copy> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> + </xsl:template> +</xsl:stylesheet> diff --git a/misc/xml/update_to_new_format.xsl b/misc/xml/update_to_new_format.xsl new file mode 100644 index 0000000..b92f780 --- /dev/null +++ b/misc/xml/update_to_new_format.xsl @@ -0,0 +1,118 @@ +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:template match="banks"> + <xsl:apply-templates select="@*|node()"/> + </xsl:template> + <xsl:template match="views"> + <xsl:apply-templates select="@*|node()"/> + </xsl:template> + <xsl:template match="units"> + <xsl:apply-templates select="@*|node()"/> + </xsl:template> + + <xsl:template match="bank"> + <bank> + <xsl:for-each select="bank_description/*"> + <xsl:attribute name="{name()}"> + <xsl:value-of select="text()"/> + </xsl:attribute> + </xsl:for-each> + + <xsl:apply-templates select="registers/*"/> + </bank> + </xsl:template> + + <xsl:template match="bank_description"> + </xsl:template> + + <xsl:template match="register_bits"> + <field> + <xsl:for-each select="*"> + <xsl:if test="name() = 'views'"> + <xsl:apply-templates select="view"/> + </xsl:if> + <xsl:if test="name() != 'views'"> + <xsl:attribute name="{name()}"> + <xsl:value-of select="text()"/> + </xsl:attribute> + </xsl:if> + </xsl:for-each> + </field> + </xsl:template> + + <xsl:template match="register"> + <register> + <xsl:for-each select="*"> + <xsl:if test="name() = 'registers_bits'"> + <xsl:apply-templates select="register_bits"/> + </xsl:if> + <xsl:if test="name() = 'views'"> + <xsl:apply-templates select="view"/> + </xsl:if> + <xsl:if test="name() != 'registers_bits' and name() != 'views'"> + <xsl:attribute name="{name()}"> + <xsl:value-of select="text()"/> + </xsl:attribute> + </xsl:if> + </xsl:for-each> + </register> + </xsl:template> + + <xsl:template match="enum"> + <name> + <xsl:attribute name="name"> + <xsl:value-of select="text()"/> + </xsl:attribute> + <xsl:apply-templates select="@*"/> + </name> + </xsl:template> + + <xsl:template match="view[@type]"> + <xsl:if test="@type = 'formula'"> + <transform> + <xsl:for-each select="*"> + <xsl:attribute name="{name()}"> + <xsl:value-of select="text()"/> + </xsl:attribute> + </xsl:for-each> + </transform> + </xsl:if> + <xsl:if test="@type = 'enum'"> + <enum> + <xsl:for-each select="*"> + <xsl:if test="name() != 'enum'"> + <xsl:attribute name="{name()}"> + <xsl:value-of select="text()"/> + </xsl:attribute> + </xsl:if> + </xsl:for-each> + <xsl:apply-templates select="enum"/> + </enum> + </xsl:if> + </xsl:template> + + <xsl:template match="view"> + <view> + <xsl:attribute name="name"><xsl:value-of select="text()"/></xsl:attribute> + </view> + </xsl:template> + + <xsl:template match="convert_unit"> + <transform> + <xsl:attribute name="unit"><xsl:value-of select="@value"/></xsl:attribute> + <xsl:attribute name="transform"><xsl:value-of select="text()"/></xsl:attribute> + </transform> + </xsl:template> + + <xsl:template match="unit"> + <unit> + <xsl:apply-templates select="@*"/> + <xsl:apply-templates select="convert_unit"/> + </unit> + </xsl:template> + + <xsl:template match="@*|node()"> + <xsl:copy> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> + </xsl:template> +</xsl:stylesheet> |