<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text"/>
    <xsl:variable name="macro-call">WPInteropStyles.</xsl:variable>
    <xsl:template match="/">
       

function SetStyle(style as string)
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Template"
args1(0).Value = style
args1(1).Name = "Family"
args1(1).Value = 2

dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1())

args1(1).Value = 1

dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1())

end function

 <xsl:apply-templates select="//@*[contains(., $macro-call)]"/>
       </xsl:template>

    <xsl:template match="@*">
        <xsl:variable name="macro-name" select="substring-after(., $macro-call)"/> 
        <xsl:variable name="style-name" >
            <xsl:call-template name="unescape-style-name">
                <xsl:with-param name="style-name" select="substring-before($macro-name, '(')"/>
            </xsl:call-template>
        </xsl:variable>
        
Sub <xsl:value-of select="$macro-name"/> 
         SetStyle("<xsl:value-of select="$style-name"/>" ) 
end Sub 
    
    
   </xsl:template>
 
    <xsl:template name="unescape-style-name">
        <xsl:param name="style-name"/>
        <xsl:choose>
            <xsl:when test="starts-with($style-name, 'ii')">
                <xsl:value-of select="concat('i-', substring-after($style-name, 'ii') )"/>
            </xsl:when>
            <xsl:when test="contains($style-name, 'num')">
                <xsl:value-of select="concat(substring-before($style-name, 'num') , '#' )"/>
            </xsl:when>
           <xsl:when test="contains($style-name, 'bull')">
                <xsl:value-of select="concat(substring-before($style-name, 'bull') , '*' )"/>
           </xsl:when>
             <xsl:when test="contains($style-name, 'alpha')">
                <xsl:value-of select="concat(substring-before($style-name, 'alpha') , 'A' )"/>
             </xsl:when>
             <xsl:when test="contains($style-name, 'rom')">
                <xsl:value-of select="concat(substring-before($style-name, 'alpha') , 'I' )"/>
             </xsl:when>
            <xsl:otherwise><xsl:value-of select="$style-name"/></xsl:otherwise>
            
            
        </xsl:choose>
        
     </xsl:template>
    
    
</xsl:stylesheet>
