jpegvarn
asked on
Tweaks needed for XSL sheet (using Saxon) - outputting to Excel file now
Hello guys,
Here is my current XSL...everything is fine, but here is the rest of what I need plus a question...thank you.
1. I have the column names (excel sheet) coming in as the field names from the database and would like to rename them. I tried to use -> msxsl:node-set($vColumnLab els)/label [@id = current()/@name] -> but I got the following error: "The URI urn:schemas-microsoft=ocm: xslt does not identify an external Java class"
2. Do I have to specify the output file name (results.xml)? I'm testing right now, but think its a temp file and the name could change... -> <xsl:variable name="input" select="document('results. xml')"/>
3. Is there a way to align all the data to the left (some on the left, some on the right)?
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
extension-element-prefixes ="saxon" version="1.0">
<xsl:variable name="vColumnLabels">
</xsl:variable>
<xsl:variable name="input" select="document('results. xml')"/>
<xsl:template match="/">
<xsl:variable name="filename">
<xsl:if test="function-available(' date:to-st ring') and function-available('date:n ew')">
<xsl:value-of select="concat(translate(d ate:to-str ing(date:n ew()),':', ''),'.xls' )"/>
</xsl:if>
</xsl:variable>
<saxon:output href="{$filename}" method="text">
<xsl:for-each select="$input/ResultSet/R esultSetDa ta/Row[1]/ Column">
<xsl:value-of select="@name"/>
<xsl:text>	</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text >
<xsl:for-each select="$input/ResultSet/R esultSetDa ta/Row">
<xsl:for-each select="Column" >
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">
<xsl:text>	</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text >
</xsl:for-each>
</saxon:output>
</xsl:template>
</xsl:stylesheet>
Here is my current XSL...everything is fine, but here is the rest of what I need plus a question...thank you.
1. I have the column names (excel sheet) coming in as the field names from the database and would like to rename them. I tried to use -> msxsl:node-set($vColumnLab
2. Do I have to specify the output file name (results.xml)? I'm testing right now, but think its a temp file and the name could change... -> <xsl:variable name="input" select="document('results.
3. Is there a way to align all the data to the left (some on the left, some on the right)?
XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
extension-element-prefixes
<xsl:variable name="vColumnLabels">
</xsl:variable>
<xsl:variable name="input" select="document('results.
<xsl:template match="/">
<xsl:variable name="filename">
<xsl:if test="function-available('
<xsl:value-of select="concat(translate(d
</xsl:if>
</xsl:variable>
<saxon:output href="{$filename}" method="text">
<xsl:for-each select="$input/ResultSet/R
<xsl:value-of select="@name"/>
<xsl:text>	</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text
<xsl:for-each select="$input/ResultSet/R
<xsl:for-each select="Column" >
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">
<xsl:text>	</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text
</xsl:for-each>
</saxon:output>
</xsl:template>
</xsl:stylesheet>
post your original XML document please :)
hi jpegvarn
It’s me again, I have rewritten the style sheet to produce a base XML file using Microsoft schema.
The style sheet now will produce an Excel file but we should be able to apply formatting to the cells as well.
To start with aligned everything to the left so you can see.
Can you please give more details about the other changes you looking for
************** NEW SHEET *************
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
extension-element-prefixes ="saxon" version="1.0">
<xsl:variable name="input" select="document('ResultSe t.xml')"/>
<xsl:template match="/">
<xsl:variable name="filename">
<xsl:if test="function-available(' date:to-st ring') and function-available('date:n ew')">
<xsl:value-of select="concat(translate(d ate:to-str ing(date:n ew()),':', ''),'.xls' )"/>
</xsl:if>
</xsl:variable>
<saxon:output href="{$filename}" method="xml">
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
</OfficeDocumentSettings>
<Styles>
<Style ss:ID="Data1">
<Alignment ss:Horizontal="Left"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<xsl:for-each select="$input/ResultSet/R esultSetDa ta/Row[1]/ Column">
<Cell ss:StyleID="Data1"><Data ss:Type="String">
<xsl:value-of select="@name"/></Data></C ell>
</xsl:for-each>
</Row>
<xsl:for-each select="$input/ResultSet/R esultSetDa ta/Row">
<Row>
<xsl:for-each select="Column">
<Cell ss:StyleID="Data1">
<Data ss:Type="String">
<xsl:value-of select="."/>
</Data></Cell>
</xsl:for-each>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</saxon:output>
</xsl:template>
</xsl:stylesheet>
It’s me again, I have rewritten the style sheet to produce a base XML file using Microsoft schema.
The style sheet now will produce an Excel file but we should be able to apply formatting to the cells as well.
To start with aligned everything to the left so you can see.
Can you please give more details about the other changes you looking for
************** NEW SHEET *************
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
extension-element-prefixes
<xsl:variable name="input" select="document('ResultSe
<xsl:template match="/">
<xsl:variable name="filename">
<xsl:if test="function-available('
<xsl:value-of select="concat(translate(d
</xsl:if>
</xsl:variable>
<saxon:output href="{$filename}" method="xml">
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.org/TR/REC-html40">
<OfficeDocumentSettings xmlns="urn:schemas-microso
</OfficeDocumentSettings>
<Styles>
<Style ss:ID="Data1">
<Alignment ss:Horizontal="Left"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<xsl:for-each select="$input/ResultSet/R
<Cell ss:StyleID="Data1"><Data ss:Type="String">
<xsl:value-of select="@name"/></Data></C
</xsl:for-each>
</Row>
<xsl:for-each select="$input/ResultSet/R
<Row>
<xsl:for-each select="Column">
<Cell ss:StyleID="Data1">
<Data ss:Type="String">
<xsl:value-of select="."/>
</Data></Cell>
</xsl:for-each>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</saxon:output>
</xsl:template>
</xsl:stylesheet>
ASKER
#3 works, thank you...
1. I have the column names (excel sheet) coming in as the field names from the database and would like to rename them. I tried to use -> msxsl:node-set($vColumnLab els)/label [@id = current()/@name] -> but I got the following error: "The URI urn:schemas-microsoft=ocm: xslt does not identify an external Java class"
--> Is there a way I can rename the column names that output to the excel file? For example, one of the names of the fields is FOR, but I want to rename it to FORWARDED so people will know what it means. So there has to be some type of IF statement in there.
2. Do I have to specify the output file name (results.xml)? I'm testing right now, but think its a temp file and the name could change... -> <xsl:variable name="input" select="document('results. xml')"/>
Like I said, as of now, the below statement tells to use the XML document ResultSet.xml. Is this 100% necessary? In the XML, I am telling it to use the XSL, so why would I need to specifiy this here? The problem is that the XML I am requesting does not come back with a predefined filename, I think its a temp file that gets changed...does that make sense?
<xsl:variable name="input" select="document('ResultSe t.xml')"/>
1. I have the column names (excel sheet) coming in as the field names from the database and would like to rename them. I tried to use -> msxsl:node-set($vColumnLab
--> Is there a way I can rename the column names that output to the excel file? For example, one of the names of the fields is FOR, but I want to rename it to FORWARDED so people will know what it means. So there has to be some type of IF statement in there.
2. Do I have to specify the output file name (results.xml)? I'm testing right now, but think its a temp file and the name could change... -> <xsl:variable name="input" select="document('results.
Like I said, as of now, the below statement tells to use the XML document ResultSet.xml. Is this 100% necessary? In the XML, I am telling it to use the XSL, so why would I need to specifiy this here? The problem is that the XML I am requesting does not come back with a predefined filename, I think its a temp file that gets changed...does that make sense?
<xsl:variable name="input" select="document('ResultSe
this for number 1
+++++++++++++++ NNNN++++++++++++++
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
extension-element-prefixes ="saxon" version="1.0">
<xsl:variable name="input" select="document('ResultSe t.xml')"/>
<xsl:template match="/">
<xsl:variable name="filename">
<xsl:if test="function-available(' date:to-st ring') and function-available('date:n ew')">
<xsl:value-of select="concat(translate(d ate:to-str ing(date:n ew()),':', ''),'.xls' )"/>
</xsl:if>
</xsl:variable>
<saxon:output href="{$filename}" method="xml">
<Workbook xmlns="urn:schemas-microso ft-com:off ice:spread sheet"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:x="urn:schemas-micro soft-com:o ffice:exce l"
xmlns:ss="urn:schemas-micr osoft-com: office:spr eadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<OfficeDocumentSettings xmlns="urn:schemas-microso ft-com:off ice:office ">
</OfficeDocumentSettings>
<Styles>
<Style ss:ID="Data1">
<Alignment ss:Horizontal="Left"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<xsl:for-each select="$input/ResultSet/R esultSetDa ta/Row[1]/ Column">
<Cell ss:StyleID="Data1"><Data ss:Type="String">
<xsl:choose>
<xsl:when test="@name='FOR'">
<xsl:text>FORWARDED</xsl:t ext>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</Data></Cell>
</xsl:for-each>
</Row>
<xsl:for-each select="$input/ResultSet/R esultSetDa ta/Row">
<Row>
<xsl:for-each select="Column">
<Cell ss:StyleID="Data1">
<Data ss:Type="String">
<xsl:value-of select="."/>
</Data></Cell>
</xsl:for-each>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</saxon:output>
</xsl:template>
</xsl:stylesheet>
+++++++++++++++ NNNN++++++++++++++
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon"
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
extension-element-prefixes
<xsl:variable name="input" select="document('ResultSe
<xsl:template match="/">
<xsl:variable name="filename">
<xsl:if test="function-available('
<xsl:value-of select="concat(translate(d
</xsl:if>
</xsl:variable>
<saxon:output href="{$filename}" method="xml">
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.org/TR/REC-html40">
<OfficeDocumentSettings xmlns="urn:schemas-microso
</OfficeDocumentSettings>
<Styles>
<Style ss:ID="Data1">
<Alignment ss:Horizontal="Left"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<xsl:for-each select="$input/ResultSet/R
<Cell ss:StyleID="Data1"><Data ss:Type="String">
<xsl:choose>
<xsl:when test="@name='FOR'">
<xsl:text>FORWARDED</xsl:t
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</Data></Cell>
</xsl:for-each>
</Row>
<xsl:for-each select="$input/ResultSet/R
<Row>
<xsl:for-each select="Column">
<Cell ss:StyleID="Data1">
<Data ss:Type="String">
<xsl:value-of select="."/>
</Data></Cell>
</xsl:for-each>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</saxon:output>
</xsl:template>
</xsl:stylesheet>
Q2- would you be happy to enter the processed file name at the command line only?
ASKER
Q1 works fine, thanks again.
Q2, let me do some testing on my end, but could I come back to this one? How can I contact you? Will you check on this question regualrly? Thanks.
Q2, let me do some testing on my end, but could I come back to this one? How can I contact you? Will you check on this question regualrly? Thanks.
check my profile
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi jpegvarn
Did the last bit worked for you yet?
Did the last bit worked for you yet?
ASKER
Yes, thank you very much wadalhag. Have a nice day.
Hi again jpegvarn
The points for this question didn’t com through yet. Did you press accept?
The points for this question didn’t com through yet. Did you press accept?
ASKER
All set. Thanks again.
thanks jpegvarn