2016-09-16 1 views
-2

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&#x3b; Midi Scheinpflug als Berta, seine Tochter&#x3b; Armand Zäpfel als Jaromir&#x3b; Wolf von Strobl als Boleslav&#x3b; Arnulf Schröder als Günther, Kastellan&#x3b; Albert Lippert als Ein Hauptmann&#x3b; Albert Wisheu als Ein Soldat"/> 
    </h1:Block> 
</h1:Document> 
</h1:DocumentSet>` 

그리고 나의 XSLT입니다 : 내가 동일한 위치를 표시하는 속성 "ob30"로 편집 된 요소를 원하는

<?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> 

경우 처음 xml의 ​​ob30이 시작됩니다. ob30 속성이있는 요소는 "블록"요소의 형제 요소로 나타납니다. 나는 그것을 고치는 방법을 모른다. 이것에 대한 실용적인 해결책이 있습니까?

편집 : 다음과 같은 라인을 따라

<?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&#x3b; Midi Scheinpflug als Berta, seine Tochter&#x3b; Armand Zäpfel als Jaromir&#x3b; Wolf von Strobl als Boleslav&#x3b; Arnulf Schröder als Günther, Kastellan&#x3b; Albert Lippert als Ein Hauptmann&#x3b; 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> 
+0

당신이 우리에게 당신이 입력을 생성 할 출력을 표시 할 수 있습니다 당신이 보여 주었다 스 니펫을 여기에, 내가 원하는 출력을 추가 ? 첫 번째'Field [@ Type = 'ob30']'을 변형시키고 싶다면''match = "Field [@ Type = 'ob30'] [1]''템플릿을 작성하면 어떤 문제인지 모르겠다 if 당신은 세 번째를 변형시키고 템플릿'match = "Field [@ Type = 'ob30'] [3]"을 쓰고 싶다. –

+0

이 템플릿을 사용하면 구문 오류 "예기치 않은 토큰"이됩니다. ""끝에서 벗어납니다. " 그 이유 때문에, 나는 "ob30"을 결정하는 위치를 세어 봐야했습니다. 내 질문을 편집하여 출력을 추가합니다. –

+0

구문 오류와 관련하여 도움이 필요한 경우 다른 사람이 오류를 재현 할 수 있도록 최소한이지만 완전한 스타일 시트를 게시하십시오. –

답변

0

시도 :

<xsl:template match="Field[@Type='ob30']"/> 

<xsl:template match="Field[@Type='ob30'][1]" priority="5"> 
    <h1:Field Type="ob30" Value="Herstellung"> 
     <xsl:apply-templates select=".//Field[@Type='3100']"/> 
     <xsl:apply-templates select=".//Field[@Type='3475']"/> 
    </h1:Field> 
</xsl:template> 

<xsl:template match="Field[@Type='ob30'][3]" priority="5"> 
    <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:template> 

<xsl:template match="Field[@Type='ob30'][position() = (4, 5)]" priority="5"> 
    <h1:Field Type="ob30" Value="Inszenierung"> 
     <xsl:apply-templates select=".//Field[@Type='3100']"/> 
     <xsl:apply-templates select=".//Field[@Type='3475']"/> 
    </h1:Field> 
</xsl:template> 
+0

고맙습니다. 나는 match = "Field [@ Type = 'ob30'] [1]"을 사용하려고 할 때 뭔가 잘못 입력했습니다. –