Reputation: 383
A have following XML:
<root>
<request>
<parameters>
<DatabaseAlias>NSMFPROD</DatabaseAlias>
<open-menu>yes</open-menu>
<reports-section>_ALL</reports-section>
<_path>/PrintHelper/ui/menu.xmsql:</_path>
<P_BC_TYPE__desc>C</P_BC_TYPE__desc>
<DocumentType>MISC.EXCEL.REG.CNTF.TYPES</DocumentType>
<P_BC_TYPE>C</P_BC_TYPE>
<P_NOM_ID/>
<reports-repository>config/~reports/documents.xml</reports-repository>
<P_DATE_FROM__desc>01.01.1900</P_DATE_FROM__desc>
<p_run_document_type>MISC.EXCEL.REG.CNTF.TYPES</p_run_document_type>
<P_CRN__desc>BGN</P_CRN__desc>
<edit_reports-repository>default</edit_reports-repository>
<P_DATE_FROM>01.01.1900</P_DATE_FROM>
<sub-menu-name>run-reports</sub-menu-name>
<P_NOM_ID__desc/>
<out>debug.plain</out>
<P_CRN>BGN</P_CRN>
<P_DATE_TO>12.12.2016</P_DATE_TO>
<menu-name>test</menu-name>
<ReportRoot>
http://localhost:8080/PrintHelper/config/~reports/documents.xml
</ReportRoot>
<P_DATE_TO__desc>12.12.2016</P_DATE_TO__desc>
</parameters>
</request>
<data>
<row row="1">
<id>17912</id>
<name>MBGA1S2аа</name>
<emission>2002</emission>
<bc_type>C</bc_type>
<crn>BGN</crn>
<denom_id>1 българска стотинка</denom_id>
<wm_simulation/>
<wm_position/>
<sec_thread/>
<imitation_mcrtext/>
<foil_failure/>
<iridescent_ovi/>
<uv_paper_prop/>
<fluor_fiber/>
<pos_fiber/>
<fluor_ink/>
<ir_prop_ink/>
<intaglio/>
<min_lettering/>
<sn_readability/>
<register_purposely_reproduct>Не</register_purposely_reproduct>
<prod_method/>
<production_method_notes/>
<reg_date>01.01.1900</reg_date>
<first_usage_date/>
<diameter>0</diameter>
<weight>0</weight>
<gurt_imitation>Не</gurt_imitation>
<alloy/>
<colour/>
<magnetic_property/>
<coins_sound/>
<mint_mark/>
</row>
</data>
</root>
And this helper.xml:
<?xml version='1.0' encoding='windows-1251' ?>
<!-- $Id: ant.xml 5894 2011-04-05 07:57:57Z dtoshova $ -->
<root>
<report code="EXCEL.MISC.POLICE" name="За органите на МВР">
<ant>
<report code="MISC.EXCEL.REG.CNTF.TYPES" name="Регистрирани типове">
<ant>
<column dataStyle="Text" dataType="Number" src="id" width="40" bc_type="BC" crn_code="BGN EUR USD">
<text>ID</text>
</column>
<column dataStyle="Text" dataType="String" src="name" width="60" bc_type="BC" crn_code="BGN-EUR-USD">
<text>Име</text>
</column>
<column dataStyle="Text" dataType="String" src="denom_id" width="60" bc_type="BC" crn_code="BGN-EUR-USD">
<text>Номинал</text>
</column>
<column dataStyle="Text" dataType="String" src="emission" width="60" bc_type="BC" crn_code="BGN EUR USD">
<text>Емисия</text>
</column>
<column dataStyle="Text" dataType="String" src="wm_simulation" width="100" bc_type="B" crn_code="BGN">
<text>Имитация на полутоновия воден знак</text>
</column>
<column dataStyle="Text" dataType="String" src="wm_position" width="100" bc_type="B" crn_code="BGN">
<text>Разположение на полутоновия воден знак</text>
</column>
<column dataStyle="Text" dataType="String" src="sec_thread" width="70" bc_type="B" crn_code="BGN">
<text>Осигурителна нишка</text>
</column>
<column dataStyle="Text" dataType="String" src="imitation_mcrtext" width="70" bc_type="B" crn_code="BGN">
<text>Имитация на микротекст в осигурителната нишка</text>
</column>
<column dataStyle="Text" dataType="String" src="foil_failure" width="70" bc_type="B" crn_code="BGN">
<text>Холограмно фолио</text>
</column>
<column dataStyle="Text" dataType="String" src="iridescent_ovi" width="70" bc_type="B" crn_code="BGN">
<text>OVI мастило</text>
</column>
<column dataStyle="Text" dataType="String" src="uv_paper_prop" width="70" bc_type="B" crn_code="BGN">
<text>UV свойства на хартията</text>
</column>
<column dataStyle="Text" dataType="String" src="fluor_fiber" width="70" bc_type="B" crn_code="BGN">
<text>Флуоресциращи влакънца</text>
</column>
<column dataStyle="Text" dataType="String" src="pos_fiber" width="70" bc_type="B" crn_code="BGN">
<text>Разположение на флуоресциращите влакънца</text>
</column>
<column dataStyle="Text" dataType="String" src="fluor_ink" width="70" bc_type="B" crn_code="BGN">
<text>Флуоресциращи мастила</text>
</column>
<column dataStyle="Text" dataType="String" src="ir_prop_ink" width="70" bc_type="B" crn_code="BGN">
<text>IR (инфрачервени) свойства на мастилата</text>
</column>
<column dataStyle="Text" dataType="String" src="intaglio" width="70" bc_type="B" crn_code="BGN">
<text>Релефен печат</text>
</column>
<column dataStyle="Text" dataType="String" src="min_lettering" width="70" bc_type="B" crn_code="BGN">
<text>Микро- или мини текст</text>
</column>
<column dataStyle="Text" dataType="String" src="sn_readability" width="70" bc_type="B" crn_code="BGN">
<text>Сериен номер - четимост</text>
</column>
<column dataStyle="Text" dataType="String" src="register_purposely_reproduct" width="70" bc_type="B" crn_code="BGN">
<text>Преднамерено възпроизведен регистър на проглед</text>
</column>
<column dataStyle="Text" dataType="String" src="diameter" width="70" bc_type="C" crn_code="BGN">
<text>Диаметър</text>
</column>
<column dataStyle="Text" dataType="String" src="weight" width="70" bc_type="C" crn_code="BGN">
<text>Тегло</text>
</column>
<column dataStyle="Text" dataType="String" src="gurt_imitation" width="70" bc_type="C" crn_code="BGN">
<text>Имитация на гурт</text>
</column>
<column dataStyle="Text" dataType="String" src="alloy" width="70" bc_type="C" crn_code="BGN">
<text>Сплав</text>
</column>
<column dataStyle="Text" dataType="String" src="colour" width="70" bc_type="C" crn_code="BGN">
<text>Цвят</text>
</column>
<column dataStyle="Text" dataType="String" src="magnetic_property" width="70" bc_type="C" crn_code="BGN">
<text>Магнитни свойства</text>
</column>
<column dataStyle="Text" dataType="String" src="coins_sound" width="70" bc_type="C" crn_code="BGN">
<text>Звук</text>
</column>
<column dataStyle="Text" dataType="String" src="mint_mark" width="70" bc_type="C" crn_code="EUR">
<text>Mint mark</text>
</column>
<column dataStyle="Text" dataType="String" src="prod_method" width="70" bc_type="BC" crn_code="BGN-EUR-USD">
<text>Начин на производство</text>
</column>
<column dataStyle="Text" dataType="String" src="production_method_notes" width="100" bc_type="BC" crn_code="BGN-EUR-USD">
<text>Бележки - начин на производство</text>
</column>
<column dataStyle="Text" dataType="String" src="reg_date" width="30" bc_type="BC" crn_code="BGN-EUR-USD">
<text>Дата на създаване</text>
</column>
<column dataStyle="Text" dataType="String" src="first_usage_date" width="30" bc_type="BC" crn_code="BGN">
<text>Дата на първо регистриране</text>
</column>
</ant>
<params>
<param code="P_BC_TYPE" name="вид"/>
<param code="P_CRN" name="валута"/>
<param code="P_NOM_ID" name="номинал"/>
<param code="P_DATE_FROM" name="от дата"/>
<param code="P_DATE_TO" name="до дата"/>
</params>
</report>
</root>
I have this xsl transformation:
<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:debug="urn:local:debug"
xmlns:exslt="http://exslt.org/common">
<xsl:import href="../excel-styles.xsl"/>
<xsl:import href="../excel-common.xsl"/>
<!--select="document('../../documents.xml')/documents/section/type[@code = $local.document.type]"/-->
<xsl:param name="local.document" select="//request/parameters/DocumentType"/>
<xsl:param name="local.helper" select="document('helper.xml')/root/report[@code = $local.document]"/>
<xsl:param name="local.params.values" select="document('params.xml')/root"/>
<xsl:param name="local.params" select="//request/parameters"/>
<xsl:output method="xml" indent="yes" encoding="windows-1251"/>
<xsl:template match="/">
<xsl:processing-instruction name="mso-application">
<xsl:text>progid="Excel.Sheet"</xsl:text>
</xsl:processing-instruction>
<Workbook>
<xsl:call-template name="excel.xsl-processor-info"/>
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>
<xsl:text>$Id: $</xsl:text>
</Author>
<Created/>
</DocumentProperties>
<Styles>
<xsl:call-template name="excel.styles.static"/>
</Styles>
<Worksheet ss:Name="report">
<Table>
<xsl:apply-templates select="$local.helper/params/param" mode="param_row">
<xsl:with-param name="paramset" select="//parameters"/>
<xsl:with-param name="dataparamset" select="//data_parameters"/>
</xsl:apply-templates>
</Table>
<xsl:call-template name="types_sheet"/>
</Worksheet>
</Workbook>
</xsl:template>
<!--Отделните таблици на типовете-->
<xsl:template name="types_sheet">
<Table>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="//P_BC_TYPE"/>
</ss:Data>
</Cell>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="//P_CRN"/>
</ss:Data>
</Cell>
<xsl:apply-templates select="$local.helper/ant/column[contains (@bc_type,//P_BC_TYPE)][contains (@crn_code,//P_CRN)]" mode="dd"/>
<!--широчината на колоните-->
<xsl:apply-templates select="$local.helper/ant/column[contains (@bc_type,//P_BC_TYPE)][contains (@crn_code,//P_CRN)]" mode="columns_width">
<xsl:with-param name="columns" select="$local.params"/>
</xsl:apply-templates>
<!--антетката-->
<Row>
<xsl:apply-templates select="$local.helper/ant/column[contains (@bc_type,//P_BC_TYPE)][contains (@crn_code,//P_CRN)]" mode="ant_cells">
<xsl:with-param name="columns" select="$local.params"/>
</xsl:apply-templates>
</Row>
<!--данните-->
<xsl:apply-templates select="//data/row[crn=//P_CRN][bc_type=//P_BC_TYPE]" mode="data_rows">
</xsl:apply-templates>
</Table>
</xsl:template>
<xsl:template match="column" mode="dd">
<Row>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="column/text"/>
</ss:Data>
</Cell>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="@bc_type"/>
</ss:Data>
</Cell>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="@crn_code"/>
</ss:Data>
</Cell>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="//P_BC_TYPE"/>
</ss:Data>
</Cell>
<Cell ss:StyleID="cellBold">
<ss:Data ss:Type="String">
<xsl:value-of select="//P_CRN"/>
</ss:Data>
</Cell>
</Row>
</xsl:template>
</xsl:stylesheet>
The problem is that when i select first time //P_BC_TYPE and //P_CRN in
xsl:template match="/">
it return C and BGN, but when select them in
xsl:template match="column" mode="dd">
it return to me empty string(even when I select them with /root/request/parameters/P_BC_TYPE). Why XPath can not find them?
Upvotes: 0
Views: 382
Reputation: 2177
It does not work because the context node of that template is in the other xml document, so the xpath will be evaluated against that. The solution is not so difficult:
create a new variable (below your params)
<xsl:variable name="origdoc" select="/"/>
and where you need the xpath, use it with the $origdoc e.g.: (no need for //
, it will start at the top of $origdoc anyway)
<xsl:value-of select="$origdoc/P_BC_TYPE"/>
Upvotes: 1