Я пытаюсь внести изменения в документ XML, и у меня возникли проблемы с вставкой группы элементов, которые легко редактируются в XSLT, - в конкретных должность. так что здесь мы идем, это XML:XSLT: Как вставить отредактированные элементы в определенной позиции в документе XML
`<?xml version="1.0" encoding="UTF-8"?>
<h1:DocumentSet xmlns:h1="http://www.startext.de/HiDA/DefService/XMLSchema">
<h1:ContentInfo>
<h1:Format>HIDA-DOC1-XML</h1:Format>
<h1:CreationDate>21.04.2016 14:17:30:042</h1:CreationDate>
</h1:ContentInfo>
<h1:Document DocKey="obj 00000003" FieldsCount="286">
<h1:Block Type="obj" CreationDate="03.02.2014 11:43:26" CreatorID="Admin" ChangeDate="21.01.2015 10:29:20" ChangerID="Admin" OwnerID="Admin" FieldsCount="220">
<h1:Field Type="5000" Value="00000003"/>
<h1:Field Type="9920" Value="1931.03.07"/>
<h1:Field Type="ob28" Value="TWS">
<h1:Field Type="2800"/>
<h1:Field Type="2864" Value="München"/>
<h1:Field Type="2862" Value="unbekannt"/>
<h1:Field Type="2930" Value="Fotoabteilung"/>
<h1:Field Type="2950" Value="TWS_FGL00001"/>
<h1:Field Type="907d" Value="No. 231"/>
</h1:Field>
<h1:Field Type="5108" Value="München">
<h1:Field Type="5110" Value="Theater unbekannt"/>
</h1:Field>
<h1:Field Type="ob30">
<h1:Field Type="3100" Value="unbekannt"/>
<h1:Field Type="3475" Value="Fotograf/in, Atelier"/>
</h1:Field>
<h1:Field Type="ob30">
<h1:Field Type="3100" Value="unbekannt"/>
<h1:Field Type="3475" Value="Verlag"/>
</h1:Field>
<h1:Field Type="ob30">
<h1:Field Type="3100" Value="Grillparzer, Franz"/>
<h1:Field Type="3475" Value="Autor/in"/>
</h1:Field>
<h1:Field Type="ob30">
<h1:Field Type="3100" Value="Böhm, Karl Hans"/>
<h1:Field Type="3475" Value="Regie"/>
</h1:Field>
<h1:Field Type="ob30">
<h1:Field Type="3100" Value="Linnebach, Adolf"/>
<h1:Field Type="3475" Value="Bühnenbild"/>
</h1:Field>
<h1:Field Type="5200" Value="Ahnfrau, Die"/>
<h1:Field Type="5220" Value="Fotografie"/>
<h1:Field Type="5226" Value="Negativ"/>
<h1:Field Type="5230" Value="Glasplattennegativ"/>
<h1:Field Type="agZeit"/>
<h1:Field Type="agThema"/>
<h1:Field Type="5360" Value="18x13"/>
<h1:Field Type="55th" Value="Zäpfel, Armand"/>
<h1:Field Type="8450">
<h1:Field Type="8470"/>
<h1:Field Type="8540" Value="F:\Glasplattennegative\JPEG\TWS_FGL00001"/>
<h1:Field Type="8555" Value="F:\Glasplattennegative\JPEG\TWS_FGL_00001"/>
<h1:Field Type="8555mf" Value="F:\Glasplattennegative\JPEG\TWS_FGL_00001"/>
<h1:Field Type="8e01" Value="TWS_FGL00001.jpg"/>
<h1:Field Type="8e02" Value="3347"/>
<h1:Field Type="8e03" Value="4598"/>
<h1:Field Type="8e04" Value="24"/>
<h1:Field Type="8e05" Value="355049"/>
<h1:Field Type="8e06" Value="Perfection V700/V750"/>
<h1:Field Type="8e07" Value="EPSON"/>
<h1:Field Type="8e08" Value="2014:02:06 14:16:13"/>
</h1:Field>
<h1:Field Type="9990" Value="Fritz Basil als Graf von Borotin; Midi Scheinpflug als Berta, seine Tochter; Armand Zäpfel als Jaromir; Wolf von Strobl als Boleslav; Arnulf Schröder als Günther, Kastellan; Albert Lippert als Ein Hauptmann; Albert Wisheu als Ein Soldat"/>
</h1:Block>
</h1:Document>
</h1:DocumentSet>`
А вот мой XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:h1="http://www.startext.de/HiDA/DefService/XMLSchema"
xpath-default-namespace="http://www.startext.de/HiDA/DefService/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template name="alles" match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=".//Field[@Type='9920']">
<h1:Field Type="5060" Value="Aufnahme">
<h1:Field Type="5064" Value="{@Value}"/>
</h1:Field>
</xsl:template>
<xsl:template match=".//Field[@Type='ob28']">
<h1:Field Type="ob28" Value="Verwalter">
<h1:Field Type="2864" Value="Köln"/>
<h1:Field Type="2900" Value="{@Value}"/>
<xsl:apply-templates select=".//Field[@Type='2930']"/>
<xsl:apply-templates select=".//Field[@Type='2950']"/>
<xsl:apply-templates select=".//Field[@Type='907d']"/>
</h1:Field>
</xsl:template>
<xsl:template match=".//Field[@Type='5108']">
<h1:Field Type="ob26" Value="Aufnahmeort">
<h1:Field Type="2664" Value="{@Value}"/>
<h1:Field Type="2690" Value="Theater"/>
<h1:Field Type="2700" Value="{.//Field/@Value}"/>
</h1:Field>
</xsl:template>
<xsl:template match=".//Field[@Type='ob30']"/>
<!-- To Do: here is my problem! i want it to appear exact same position, where the first ob30 in xml starts
<xsl:template match=".//Block">
<xsl:call-template name="alles"/>
<xsl:for-each select=".//Field[@Type='ob30']">
<xsl:if test="position()= 1">
<h1:Field Type="ob30" Value="Herstellung">
<xsl:apply-templates select=".//Field[@Type='3100']"/>
<xsl:apply-templates select=".//Field[@Type='3475']"/>
</h1:Field>
</xsl:if>
<xsl:if test="position()= 3">
<h1:Field Type="ob30" Value="Darstellung">
<xsl:apply-templates select=".//Field[@Type='3100']"/>
<xsl:apply-templates select=".//Field[@Type='3475']"/>
<h1:Field Type="5013" Value="xTITELx"/>
</h1:Field>
</xsl:if>
<xsl:if test="position()= 4 or position()= 5">
<h1:Field Type="ob30" Value="Inszenierung">
<xsl:apply-templates select=".//Field[@Type='3100']"/>
<xsl:apply-templates select=".//Field[@Type='3475']"/>
</h1:Field>
</xsl:if>
</xsl:for-each>
</xsl:template>
-->
<xsl:template match=".//Field[@Type='5226']">
<h1:Field Type="5230" Value="{@Value}"/>
</xsl:template>
<xsl:template match=".//Field[@Type='5230']">
<h1:Field Type="5240" Value="{@Value}"/>
</xsl:template>
<xsl:template match=".//Field[@Type='9990']">
<h1:Field Type="599a" Value="Werkkommentar">
<h1:Field Type="599e" Value="{@Value}"/>
<h1:Field Type="599n" Value="P,N"/>
</h1:Field>
<h1:Field Type="9902" Value="TWS"/>
<h1:Field Type="9904" Value="P,N"/>
</xsl:template>
</xsl:stylesheet>
я хочу отредактированные элементы с атрибутом «OB30» появляться точно такое же положение, в котором первая запускается ob30 в xml. элементы с атрибутом ob30 отображаются как элементы-братья элемента «Блок». Я понятия не имею, как это исправить. У вас есть практическое решение для этого?
Edit: здесь, я добавить нужный вывод:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:h1="http://www.startext.de/HiDA/DefService/XMLSchema"
xpath-default-namespace="http://www.startext.de/HiDA/DefService/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" encoding="utf-8" />
<h1:DocumentSet xmlns:h1="http://www.startext.de/HiDA/DefService/XMLSchema">
<h1:ContentInfo>
<h1:Format>HIDA-DOC1-XML</h1:Format>
<h1:CreationDate>09.06.2015 09:31:15:408</h1:CreationDate>
</h1:ContentInfo>
<h1:Document DocKey="obj 40020000">
<h1:Block Type="obj" CreationDate="03.02.2014 11:43:26" CreatorID="Admin" ChangeDate="07.02.2014 13:29:02" ChangerID="Admin" OwnerID="Admin">
<h1:Field Type="5000" Value="40020000"/>
<h1:Field Type="5060" Value="Aufnahme">
<h1:Field Type="5064" Value="1931.03.07"/>
</h1:Field>
<h1:Field Type="ob28" Value="Verwalter">
<h1:Field Type="2864" Value="Köln"/>
<h1:Field Type="2900" Value="Theaterwissenschaftliche Sammlung, Universität zu Köln"/>
<h1:Field Type="2930" Value="Fotoabteilung"/>
<h1:Field Type="2940" Value="München"/>
<h1:Field Type="2950" Value="TWS_FGL00001"/>
<h1:Field Type="907d" Value="No. 231"/>
</h1:Field>
<h1:Field Type="ob26" Value="Aufnahmeort">
<h1:Field Type="2664" Value="München"/>
<h1:Field Type="2690" Value="Theater"/>
<h1:Field Type="2700" Value="unbekanntes Theater"/>
</h1:Field>
<h1:Field Type="ob30" Value="Herstellung">
<h1:Field Type="3100" Value="unbekannter Fotograf"/>
<h1:Field Type="3475" Value="Fotograf"/>
</h1:Field>
<h1:Field Type="5007" Value="Darstellung">
<h1:Field Type="5009" Value="Grillparzer, Franz"/>
<h1:Field Type="5010" Value="Schauspiel"/>
<h1:Field Type="5013" Value="xTITELx"/>
</h1:Field>
<h1:Field Type="ob40" Value="Inszenierung">
<h1:Field Type="4100" Value="Böhm, Karl Hans"/>
<h1:Field Type="4475" Value="Regisseur"/>
</h1:Field>
<h1:Field Type="ob40" Value="Inszenierung">
<h1:Field Type="4100" Value="Linnebach, Adolf"/>
<h1:Field Type="4475" Value="Bühnenbildner"/>
</h1:Field>
<h1:Field Type="5200" Value="Die Ahnfrau"/>
<h1:Field Type="5220" Value="Fotografie"/>
<h1:Field Type="5230" Value="Negativ"/>
<h1:Field Type="5240" Value="Glasplattennegativ"/>
<h1:Field Type="5360" Value="18x13"/>
<h1:Field Type="55th" Value="unbekannt"/>
<h1:Field Type="8450" Value="digitale Reproduktion">
<h1:Field Type="8540" Value="TWS_FGL00001"/>
<h1:Field Type="8494" Value="1931.03.07"/>
<h1:Field Type="8555" Value="F:\Glasplattennegative\JPEG\TWS_FGL_00001"/>
<h1:Field Type="8555mf" Value="F:\Glasplattennegative\JPEG\TWS_FGL_00001"/>
<h1:Field Type="8e01" Value="TWS_FGL00001.jpg"/>
<h1:Field Type="8e02" Value="3347"/>
<h1:Field Type="8e03" Value="4598"/>
<h1:Field Type="8e04" Value="24"/>
<h1:Field Type="8e05" Value="355049"/>
<h1:Field Type="8e06" Value="Perfection V700/V750"/>
<h1:Field Type="8e07" Value="EPSON"/>
<h1:Field Type="8e08" Value="2014:02:06 14:16:13"/>
</h1:Field>
<h1:Field Type="599a" Value="Werkkommentar">
<h1:Field Type="599e" Value="Fritz Basil als Graf von Borotin; Midi Scheinpflug als Berta, seine Tochter; Armand Zäpfel als Jaromir; Wolf von Strobl als Boleslav; Arnulf Schröder als Günther, Kastellan; Albert Lippert als Ein Hauptmann; Albert Wisheu als Ein Soldat"/>
<h1:Field Type="599n" Value="P,N"/>
</h1:Field>
<h1:Field Type="9902" Value="TWS"/>
<h1:Field Type="9904" Value="P,N"/>
</h1:Block>
</h1:Document>
</h1:DocumentSet>
Можете ли вы показать нам вывод, который вы хотите создать для ввода фрагмент кода вы показали ? Я не уверен, какая у вас проблема, если вы хотите преобразовать первое поле [@ Type = 'ob30'] ', тогда напишите шаблон' match = "Поле [@ Type = 'ob30'] [1]" 'if вы хотите преобразовать третий, затем напишите шаблон 'match =" Поле [@ Type = 'ob30'] [3] "и так далее. –
Если я использую этот шаблон, я становлюсь синтаксической ошибкой «Неожиданный токен»] «за пределами выражения». по этой причине мне пришлось подсчитать позицию, чтобы определить «ob30». Я отредактирую свой вопрос, чтобы добавить результат. –
Если вам нужна помощь с синтаксической ошибкой, отправьте минимальную, но полную таблицу стилей, позволяющую другим воспроизвести ошибку. –