MarkLogic TDE xpath在多个重复字段上

时间:2018-05-31 10:27:12

标签: xml marklogic marklogic-9

我需要使用TDE创建模板。最终我希望能够使用我的视图查看数据。我看到的问题是因为我的xml中有多个重复元素。任何人都可以帮助我如何创建这样的模板。以下是xml的示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create - My ASP.NET Application</title>
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>

<script src="/Scripts/modernizr-2.6.2.js"></script>

</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">

            <img src="/Images/logo.jpg" width="576" height="73" />

        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/About">About</a></li>
                <li><a href="/Home/Contact">Contact</a></li>
                <li><a href="/ProjectLists">Projects</a></li>
                <li><a href="/Housekeeping">Housekeeping</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container body-content">



<!--<h2>Create New Project</h2>-->
<br />

<form action="/ProjectLists/Create" method="post">    <div class="form-horizontal">
    <h4>Create New Project</h4>
    <hr />


    <div class="form-group">
        <label class="control-label col-md-2" for="Project_Type">Project Type</label>
        <div id="ddlDiv" class="col-md-10">



<select id="pType" name="ProjTypeName"><option value="">Select option</option>
<option value="1">DCO</option>
<option value="2">CPO</option>
<option value="3">TWA</option>
</select>
<label id="ptid">

</label>

<!--<script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"> 
</script>-->
<script type="text/javascript" language="javascript">

$("#pType").change(function () {
    debugger;
    $.ajax({
        url: "ProjectTypes/_ListProjectTypes",
        method: "POST",
        data: "TypeID=" + $(this).val(),
        dataType: "json",
        success: function (response) {
            window.location.reload();
        $("#ptid").val = $(this).val()
            // handle
        }
    });
});
</script>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2" for="ProjectReference">ProjectReference</label>
        <div class="col-md-10">
            <input class="form-control text-box single-line" id="ProjectReference" name="ProjectReference" type="text" value="" />
            <span class="field-validation-valid text-danger" data-valmsg-for="ProjectReference" data-valmsg-replace="true"></span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2" for="ProjectName">ProjectName</label>
        <div class="col-md-10">
            <input class="form-control text-box single-line" id="ProjectName" name="ProjectName" type="text" value="" />
            <span class="field-validation-valid text-danger" data-valmsg-for="ProjectName" data-valmsg-replace="true"></span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2" for="ProjectDescription">ProjectDescription</label>
        <div class="col-md-10">
            <input class="form-control text-box single-line" id="ProjectDescription" name="ProjectDescription" type="text" value="" />
            <span class="field-validation-valid text-danger" data-valmsg-for="ProjectDescription" data-valmsg-replace="true"></span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2" for="ProjectManager">ProjectManager</label>
        <div class="col-md-10">
            <input class="form-control text-box single-line" id="ProjectManager" name="ProjectManager" type="text" value="" />
            <span class="field-validation-valid text-danger" data-valmsg-for="ProjectManager" data-valmsg-replace="true"></span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2" for="DateStart">DateStart</label>
        <div class="col-md-10">
            <input class="form-control text-box single-line" data-val="true" data-val-date="The field DateStart must be a date." id="DateStart" name="DateStart" type="datetime" value="" />
            <span class="field-validation-valid text-danger" data-valmsg-for="DateStart" data-valmsg-replace="true"></span>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2" for="DateCompleted">DateCompleted</label>
        <div class="col-md-10">
            <input class="form-control text-box single-line" data-val="true" data-val-date="The field DateCompleted must be a date." id="DateCompleted" name="DateCompleted" type="datetime" value="" />
            <span class="field-validation-valid text-danger" data-valmsg-for="DateCompleted" data-valmsg-replace="true"></span>
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>

</div>
</form>
<div>
<a href="/ProjectLists">Back to List</a>
</div>


    <hr />
    <footer>
        <p>&copy; 2018  - Logged in as Ardent-HP\Ardent</p>
    </footer>
</div>

<script src="/Scripts/jquery-1.10.2.js"></script>

<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>



<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Chrome","requestId":"ca5d6b107cc64804abbd651be07c37d8"}
</script>
<script type="text/javascript" 
src="http://localhost:54821/a94212cdd4c04322a8b3d6a88ccab368/browserLink" 
async="async"></script>
<!-- End Browser Link -->

</body>
</html>

我希望在这种情况下看到6行可重复字段的组合,即系列和位置。任何帮助都会非常值得赞赏。

1 个答案:

答案 0 :(得分:3)

找到使用嵌套模板的方法。这是一个示例模板:

<template xmlns="http://marklogic.com/xdmp/tde">
  <context>entity</context>
  <rows>
    <row>
      <schema-name>main</schema-name>
      <view-name>root</view-name>
      <view-layout>sparse</view-layout>
      <columns>
        <column>
          <name>id</name>
          <scalar-type>string</scalar-type>
          <val>id</val>
        </column>
        <column>
          <name>name</name>
          <scalar-type>string</scalar-type>
          <val>name</val>
        </column>        
    </columns>
    </row>
  </rows>

  <templates>
    <template>
      <context>series</context>
      <rows>
        <row>
          <schema-name>main</schema-name>
          <view-name>series</view-name>
          <view-layout>sparse</view-layout>
          <columns>
            <column>
              <name>idParent</name>
              <scalar-type>string</scalar-type>
              <val>../id</val>              
            </column>

            <column>
              <name>series</name>
              <scalar-type>string</scalar-type>
              <val>fn:string(.)</val>
              <nullable>true</nullable>
            </column>
          </columns>
        </row>
      </rows>
    </template>
    <template>
      <context>location</context>
      <rows>
        <row>
          <schema-name>main</schema-name>
          <view-name>location</view-name>
          <view-layout>sparse</view-layout>
          <columns> 
            <column>
              <name>idParentlocation</name>
              <scalar-type>string</scalar-type>
              <val>../id</val>              
            </column>
            <column>
              <name>name</name>
              <scalar-type>string</scalar-type>
              <val>fn:string(.)</val>
              <nullable>true</nullable>
            </column>
          </columns>
        </row>
      </rows>
    </template>
  </templates>  
</template>

这是sql查询:

select * from main.root 
join main.location on main.location.idParentlocation = main.root.id
join main.series on main.series.idParent = main.root.id