0
То, что я пытаюсь получить из атрибута.Извлечение значения атрибута из неконтекстного элемента
Вот входной XML:
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
\t <office:scripts/>
\t <office:font-face-decls>
\t \t <style:font-face style:name="Mangal1" svg:font-family="Mangal"/>
\t \t <style:font-face style:name="Calibri" svg:font-family="Calibri" style:font-family-generic="roman" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Calibri Light" svg:font-family="'Calibri Light'" style:font-family-generic="roman" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Cambria" svg:font-family="Cambria" style:font-family-generic="roman" style:font-pitch="variable"/>
\t \t <style:font-face style:name="DeusEx" svg:font-family="DeusEx" style:font-family-generic="roman" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Liberation Sans" svg:font-family="'Liberation Sans'" style:font-family-generic="swiss" style:font-pitch="variable"/>
\t \t <style:font-face style:name="F" svg:font-family="" style:font-family-generic="system" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="system" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Mangal" svg:font-family="Mangal" style:font-family-generic="system" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Microsoft YaHei" svg:font-family="'Microsoft YaHei'" style:font-family-generic="system" style:font-pitch="variable"/>
\t \t <style:font-face style:name="SimSun" svg:font-family="SimSun" style:font-family-generic="system" style:font-pitch="variable"/>
\t \t <style:font-face style:name="Times New Roman" svg:font-family="'Times New Roman'" style:font-family-generic="system" style:font-pitch="variable"/>
\t </office:font-face-decls>
\t <office:automatic-styles>
\t \t <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
\t \t \t <style:text-properties fo:font-size="5pt" fo:language="bg" fo:country="BG" officeooo:paragraph-rsid="00118747" style:font-size-asian="5pt" style:font-size-complex="5pt" style:language-complex="ar" style:country-complex="SA"/>
\t \t </style:style>
\t \t <style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard">
\t \t \t <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" style:writing-mode="lr-tb"/>
\t \t \t <style:text-properties officeooo:paragraph-rsid="00118747"/>
\t \t </style:style>
\t \t <style:style style:name="P3" style:family="paragraph" style:parent-style-name="Standard">
\t \t \t <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" style:writing-mode="lr-tb"/>
\t \t \t <style:text-properties fo:color="#000000" style:font-name="Cambria" fo:language="bg" fo:country="BG" officeooo:paragraph-rsid="00118747" style:font-name-complex="Arial"/>
\t \t </style:style>
\t \t <style:style style:name="P4" style:family="paragraph" style:parent-style-name="Standard">
\t \t \t <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" style:writing-mode="lr-tb"/>
\t \t \t <style:text-properties fo:color="#000000" style:font-name="Cambria" officeooo:paragraph-rsid="00118747" style:font-name-complex="Arial"/>
\t \t </style:style>
\t \t <style:style style:name="P5" style:family="paragraph" style:parent-style-name="Standard">
\t \t \t <style:paragraph-properties fo:text-align="start" style:justify-single-word="false" style:writing-mode="lr-tb"/>
\t \t \t <style:text-properties officeooo:paragraph-rsid="00118747"/>
\t \t </style:style>
\t \t <style:style style:name="P6" style:family="paragraph" style:parent-style-name="Style2">
\t \t \t <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" style:contextual-spacing="false"/>
\t \t \t <style:text-properties fo:language="bg" fo:country="BG" officeooo:paragraph-rsid="00118747"/>
\t \t </style:style>
\t \t <style:style style:name="T1" style:family="text">
\t \t \t <style:text-properties fo:font-size="20pt" style:font-size-asian="20pt"/>
\t \t </style:style>
\t \t <style:style style:name="T2" style:family="text">
\t \t \t <style:text-properties fo:font-size="20pt" fo:language="bg" fo:country="BG" style:font-size-asian="20pt"/>
\t \t </style:style>
\t \t <style:style style:name="T3" style:family="text">
\t \t \t <style:text-properties fo:color="#b22f2a" style:font-name="Calibri" fo:language="bg" fo:country="BG"/>
\t \t </style:style>
\t \t <style:style style:name="T4" style:family="text">
\t \t \t <style:text-properties fo:color="#000000" style:font-name="Cambria" fo:language="bg" fo:country="BG" style:font-name-complex="Arial"/>
\t \t </style:style>
\t \t <style:style style:name="T5" style:family="text">
\t \t \t <style:text-properties fo:color="#000000" style:font-name="Cambria" fo:language="en" fo:country="US" style:font-name-complex="Arial"/>
\t \t </style:style>
\t \t <style:style style:name="T6" style:family="text">
\t \t \t <style:text-properties fo:color="#000000" style:font-name="Cambria" style:font-name-complex="Arial"/>
\t \t </style:style>
\t </office:automatic-styles>
\t <office:body>
\t \t <office:text>
\t \t \t <text:sequence-decls>
\t \t \t \t <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
\t \t \t \t <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
\t \t \t \t <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
\t \t \t \t <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
\t \t \t </text:sequence-decls>
\t \t \t <text:p text:style-name="P6">
\t \t \t \t <text:span text:style-name="T1"/>
\t \t \t </text:p>
\t \t \t <text:p text:style-name="Title">
\t \t \t \t <text:span text:style-name="T4">Запознаване със</text:span>
\t \t \t \t <text:span text:style-name="T5">JTAG</text:span>
\t \t \t \t <text:span text:style-name="T4">протокол за програмиране на</text:span>
\t \t \t \t <text:span text:style-name="T5">MSP430</text:span>
\t \t \t \t <text:span text:style-name="T4">Запознаване с функционалността на</text:span>
\t \t \t \t <text:span text:style-name="T5">Real Time Clock.</text:span>
\t \t \t </text:p>
\t \t \t <text:p text:style-name="P5">
\t \t \t \t <text:span text:style-name="T5"/>
\t \t \t </text:p>
\t \t \t <text:p text:style-name="Subtitle">
\t \t \t \t <text:span text:style-name="T4">Създаване на</text:span>
\t \t \t \t <text:span text:style-name="Bold_20_Style">
\t \t \t \t \t <text:span text:style-name="T4">часовник</text:span>
\t \t \t \t </text:span>
\t \t \t \t <text:span text:style-name="T4">с календар в реално време.</text:span>
\t \t \t </text:p>
\t \t \t <text:p text:style-name="P5">
\t \t \t \t <text:span text:style-name="T4"/>
\t \t \t </text:p>
\t \t \t <text:h text:style-name="Heading_20_1" text:outline-level="1">
\t \t \t \t <text:span text:style-name="T4">Запознаване с</text:span>
\t \t \t \t <text:span text:style-name="T5">UART</text:span>
\t \t \t \t <text:span text:style-name="T4">периферията на</text:span>
\t \t \t \t <text:span text:style-name="T5">MSP430F5438.</text:span>
\t \t \t </text:h>
\t \t \t <text:p text:style-name="P5">
\t \t \t \t <text:span text:style-name="T5"/>
\t \t \t </text:p>
\t \t \t <text:h text:style-name="Heading_20_2" text:outline-level="2">
\t \t \t \t <text:span text:style-name="T4">Създаване на график за аларма и реализиране на прекъсвания по зададени час и дата.</text:span>
\t \t \t </text:h>
\t \t </office:text>
\t </office:body>
</office:document-content>
И это таблица стилей:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" version="1.0">
\t <xsl:output method="xml"/>
\t <!-- -->
\t <xsl:template name="return-lang">
\t \t <xsl:param name="style-name"/>
\t \t <xsl:value-of select="/office:document-content//style:style[@style:name='$style-name']/style:text-properties/@fo:language"/>
\t </xsl:template>
\t <!-- -->
\t <xsl:template name="extract-title">
\t \t <xsl:for-each select="office:body/office:text/text:p[@text:style-name='Title']">
\t \t \t <para style-name="Title">
\t \t \t \t <!--Title is a constant sinse it is a precondition-->
\t \t \t \t <xsl:for-each select="text:span">
\t \t \t \t \t <xsl:variable name="language">
\t \t \t \t \t \t <xsl:call-template name="return-lang">
\t \t \t \t \t \t \t <xsl:with-param name="style-name" select="string(@text:style-name)"/>
\t \t \t \t \t \t </xsl:call-template>
\t \t \t \t \t </xsl:variable>
\t \t \t \t \t <span xml:lan="{$language}">
\t \t \t \t \t \t <xsl:value-of select="."/>
\t \t \t \t \t </span>
\t \t \t \t </xsl:for-each>
\t \t \t </para>
\t \t </xsl:for-each>
\t </xsl:template>
\t <!-- -->
\t <xsl:template match="/office:document-content">
\t \t <text>
\t \t \t <xsl:call-template name="extract-title"/>
\t \t </text>
\t </xsl:template>
\t <!-- -->
\t <xsl:template match="text:sequence-decls">
\t \t <ofis>
\t \t \t <xsl:call-template name="extract-title"/>
\t \t </ofis>
\t </xsl:template>
\t <!-- \t <xsl:template match="@*|node()">
\t \t <xsl:copy>
\t \t \t <xsl:apply-templates select="@*|node()"/>
\t \t </xsl:copy>
\t </xsl:template> /office:document-content//style:style[@style:name='{$style-name}']/@style:family-->
</xsl:stylesheet>
Это то, что я получаю:
<text xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
<para style-name="Title">
<span xml:lan="">Запознаване със</span>
<span xml:lan="">JTAG</span>
<span xml:lan="">протокол за програмиране на</span>
<span xml:lan="">MSP430</span>
<span xml:lan="">Запознаване с функционалността на</span>
<span xml:lan="">Real Time Clock.</span>
</para>
</text>
И это то, что я ожидал:
<text>
<para style-name="Title">
<span xml:lang="bg">Запознаване със</span>
<span xml:lang="en">JTAG</span>
<span xml:lang="bg">протокол за програмиране на</span>
<span xml:lang="en">MSP430</span>
<span xml:lang="bg">Запознаване с функционалността на</span>
<span xml:lang="en">Real Time Clock.</span>
</para>
</text>
style-name
параметра. Когда я подставляю
[@style:name='$style-name']
с
[@style:name='T4']
Я получаю значение соответствующего атрибута
fo:language
. Пожалуйста, извините мой плохой английский. Пожалуйста, помогите.