XSLT Problem - Brauche ein bestimmtes Attribut

DerLukasz

Grünschnabel
Hallo zusammen!

Ich habe Folgendes Problem:
Ich muss eine XML Datei, bei der ich nicht weiss, wieviele Cellen mit verscheidenen Attributen es gibt in ein Wordformat (WordProcessingML) umwandeln.
Das klappt auch soweit:

XML-Datei:
XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.phnxsoft.com/Infoware/Protocol Protocol.xsd">
	<Data>
		<Cell attribute="VEUROPA">
			<CellValue/>
		</Cell>
		<Cell attribute="VEU">
			<CellValue/>
		</Cell>
		<Cell attribute="CR_DATE">
			<CellValue>2001-03-07 22:26:43.0</CellValue>
		</Cell>
	</Data>
	<Data>
		<Cell attribute="VEUROPA">
			<CellValue/>
		</Cell>
		<Cell attribute="VEU">
			<CellValue/>
		</Cell>
		<Cell attribute="CR_DATE">
			<CellValue>2001-03-07 22:26:47.0</CellValue>
		</Cell>
	</Data>
	<Data>
		<Cell attribute="VEUROPA">
			<CellValue/>
		</Cell>
		<Cell attribute="VEU">
			<CellValue/>
		</Cell>
		<Cell attribute="CR_DATE">
			<CellValue>2001-03-07 22:26:47.0</CellValue>
		</Cell>
	</Data>
</Table>

XSLT:
XML:
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">

	
	<xsl:output method="xml" indent="yes" />
	
	<xsl:template match="/">
		<xsl:processing-instruction name="mso-application">
			<xsl:text>progid="Word.Document"</xsl:text>
		</xsl:processing-instruction>

		<w:wordDocument>
			<w:body>
				<w:tbl>
					
					<w:tblPr>
						<w:tblStyle w:val="TableGrid"/>
							<w:tblW w:w="0" w:type="auto"/>
							<w:tblLook w:val="01E0"/>
						</w:tblPr>

					<w:tblGrid>
						<w:gridCol w:w="3070"/>
						<w:gridCol w:w="3071"/>
						<w:gridCol w:w="3071"/>
					</w:tblGrid>

					<xsl:apply-templates select="Table/Data" />
				</w:tbl>
			</w:body>
		</w:wordDocument>
	</xsl:template>



	<xsl:template match="Data">
				<w:tr>
					<xsl:apply-templates select="Cell" />
				</w:tr>
	</xsl:template>	


	<xsl:template match="Cell">
				<w:tc>
					<w:p>
						<w:r>
							<w:t>
								<xsl:apply-templates select="CellValue" />
							</w:t>
						</w:r>
					</w:p>
				</w:tc>				
	</xsl:template>

</xsl:stylesheet>


Ergebnis:
XML:
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
	<w:body>
		<w:tbl>
			<w:tblPr>
				<w:tblStyle w:val="TableGrid"/>
				<w:tblW w:w="0" w:type="auto"/>
				<w:tblLook w:val="01E0"/>
			</w:tblPr>
			<w:tblGrid>
				<w:gridCol w:w="3070"/>
				<w:gridCol w:w="3071"/>
				<w:gridCol w:w="3071"/>
			</w:tblGrid>
			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>2001-03-07 22:26:43.0</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>
			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>2001-03-07 22:26:47.0</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>
			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>2001-03-07 22:26:47.0</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>
		</w:tbl>
	</w:body>
</w:wordDocument>

Was mir jetzt noch fehlt ist, dass ich die Attribute auch gerne in einer Zeile hätte! In der ersten quasi! Habt ihr eine Idee wie ich mein XSLT ändern muss um das zu erreichen?

So soll es aussehen:
XML:
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
	<w:body>
		<w:tbl>
			<w:tblPr>
				<w:tblStyle w:val="TableGrid"/>
				<w:tblW w:w="0" w:type="auto"/>
				<w:tblLook w:val="01E0"/>
			</w:tblPr>
			<w:tblGrid>
				<w:gridCol w:w="3070"/>
				<w:gridCol w:w="3071"/>
				<w:gridCol w:w="3071"/>
			</w:tblGrid>

*ab hier was ich gern noch hätte
------------------------------------------------------------------------------

			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>VEUROPA<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>VEU<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>CR_Date</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>

------------------------------------------------------------------------------

			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>2001-03-07 22:26:43.0</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>
			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>2001-03-07 22:26:47.0</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>
			<w:tr>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t/>
						</w:r>
					</w:p>
				</w:tc>
				<w:tc>
					<w:p>
						<w:r>
							<w:t>2001-03-07 22:26:47.0</w:t>
						</w:r>
					</w:p>
				</w:tc>
			</w:tr>
		</w:tbl>
	</w:body>
</w:wordDocument>
 
Zuletzt bearbeitet von einem Moderator:
Ja das weiß ich ja,
Nur die Attribute kommen ja jedes mal in dem Tag vor.
Ich will aber jedes Attribut nur genau einmal in der ersten Zeile ausgeben lassen!

Wie würde das denn gehen?
 
Hallo,
kannst du nicht für diese erste Zeile eine for-each-Schleife machen? Die soll ja wohl nur einmal vorkommen, wenn ich das richtig verstanden habe. Alle anderen Zeilen kannst du ja wie bisher mit den Templates erledigen.
 
Ja das weiß ich ja,
Nur die Attribute kommen ja jedes mal in dem Tag vor.
Ich will aber jedes Attribut nur genau einmal in der ersten Zeile ausgeben lassen!

Wie würde das denn gehen?
Indem du nur das erste Data Element verarbeitest:
XML:
<xsl:for-each select="Data[1]/Cell/@attribute">
  ...
Gruß
 
Zuletzt bearbeitet von einem Moderator:
Zurück